pub struct FileFilter<'a> {
pub name: &'a str,
pub extensions: &'a [&'a str],
}Expand description
A named set of file extensions for a file dialog, such as
“Images” over png and jpg. Extensions are bare names,
without dots or wildcards; each backend decorates them into
its own filter syntax. How much of the grouping survives is
backend-dependent: macOS’s chooser takes one flat type list,
so there the groups merge into a single extension set.
Fields§
§name: &'a str§extensions: &'a [&'a str]Implementations§
Source§impl<'a> FileFilter<'a>
impl<'a> FileFilter<'a>
Sourcepub fn builder(name: &'a str) -> FileFilterBuilder<'a>
pub fn builder(name: &'a str) -> FileFilterBuilder<'a>
Start building a filter from its display name, as an alternative to the struct literal. Both constructions produce the same value:
use any_dialog::FileFilter;
let filter = FileFilter::builder("Images").extensions(&["png", "jpg"]);
assert_eq!(
filter,
FileFilter { name: "Images", extensions: &["png", "jpg"] }
);Examples found in repository?
examples/open_with_filters.rs (line 32)
16fn main() -> Result<(), any_dialog::Error> {
17 let dialogs = Dialogs::new();
18 if !dialogs.available() {
19 eprintln!("no dialog backend on this system (on Linux, install kdialog or zenity)");
20 return Ok(());
21 }
22
23 // Extensions are bare, without a dot or a glob: "rs", not
24 // "*.rs". Each filter is one named group in the picker. The
25 // two constructions shown are interchangeable: a struct
26 // literal, and the builder.
27 let filters = [
28 FileFilter {
29 name: "Rust source",
30 extensions: &["rs", "toml"],
31 },
32 FileFilter::builder("Text and markdown").extensions(&["txt", "md"]),
33 ];
34
35 match dialogs.prompt_open_file("Pick one file", None, &filters)? {
36 Some(path) => println!("one file: {}", path.display()),
37 None => {
38 println!("cancelled at the single picker");
39 return Ok(());
40 }
41 }
42
43 match dialogs.prompt_open_files("Pick any number of files", None, &filters)? {
44 Some(paths) => {
45 println!("{} file(s) picked:", paths.len());
46 for path in &paths {
47 println!(" {}", path.display());
48 }
49 }
50 None => println!("cancelled at the multiple picker"),
51 }
52 Ok(())
53}Trait Implementations§
Source§impl<'a> Clone for FileFilter<'a>
impl<'a> Clone for FileFilter<'a>
impl<'a> Copy for FileFilter<'a>
Source§impl<'a> Debug for FileFilter<'a>
impl<'a> Debug for FileFilter<'a>
impl<'a> Eq for FileFilter<'a>
Source§impl<'a> PartialEq for FileFilter<'a>
impl<'a> PartialEq for FileFilter<'a>
impl<'a> StructuralPartialEq for FileFilter<'a>
Auto Trait Implementations§
impl<'a> Freeze for FileFilter<'a>
impl<'a> RefUnwindSafe for FileFilter<'a>
impl<'a> Send for FileFilter<'a>
impl<'a> Sync for FileFilter<'a>
impl<'a> Unpin for FileFilter<'a>
impl<'a> UnsafeUnpin for FileFilter<'a>
impl<'a> UnwindSafe for FileFilter<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more