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.
-
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 yourCargo.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), } }