SlNPacifist / nfd-rs

Bindings to nativefiledialog in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nfd-rs

nfd-rs is a Rust binding to the library nativefiledialog, that provides a convenient cross-platform interface to opening file dialogs on Linux, OS X and Windows.

Currently, only single file and save dialogs are supported, and the crate has been tested only on OS X. And yes, APIs may break with newer versions.

Usage

  • Follow the instructions here to build the libraries in C and an OS-specific language. Then, set the NFD_LIB_DIR environment variable to the path of the directory in which the libraries are stored.

  • Add the dependency nfd in your Cargo.toml

    [dependencies]
    nfd = { git = "https://github.com/saurvs/nfd-rs.git" }
  • Open a single file dialog

    extern crate nfd;
    
    use nfd::*;
    
    fn main() {
    
      let result = open_file_dialog(None, None);
    
      match result {
          NFDResult::Okay(file_path) => println!("File path = {:?}", file_path),
          NFDResult::Cancel => println!("User canceled"),
          NFDResult::Error(error) => println!("Error: {}", error),
      }
    
    }

Screenshot

Cocoa on El Capitan

About

Bindings to nativefiledialog in Rust

License:MIT License


Languages

Language:Rust 100.0%