Skip to main content

FileFilter

Struct FileFilter 

Source
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>

Source

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>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for FileFilter<'a>

Source§

impl<'a> Debug for FileFilter<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for FileFilter<'a>

Source§

impl<'a> PartialEq for FileFilter<'a>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.