Skip to main content

FileFilterBuilder

Struct FileFilterBuilder 

Source
pub struct FileFilterBuilder<'a> { /* private fields */ }
Expand description

Builds a FileFilter from its display name, obtained from FileFilter::builder. The only way out is extensions, so a builder cannot be finished into a filter that has no extensions.

Implementations§

Source§

impl<'a> FileFilterBuilder<'a>

Source

pub fn extensions(self, extensions: &'a [&'a str]) -> FileFilter<'a>

Finish the filter with its extensions: bare names, without dots or wildcards.

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 FileFilterBuilder<'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 FileFilterBuilder<'a>

Source§

impl<'a> Debug for FileFilterBuilder<'a>

Source§

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

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

impl<'a> Eq for FileFilterBuilder<'a>

Source§

impl<'a> PartialEq for FileFilterBuilder<'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 FileFilterBuilder<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for FileFilterBuilder<'a>

§

impl<'a> RefUnwindSafe for FileFilterBuilder<'a>

§

impl<'a> Send for FileFilterBuilder<'a>

§

impl<'a> Sync for FileFilterBuilder<'a>

§

impl<'a> Unpin for FileFilterBuilder<'a>

§

impl<'a> UnsafeUnpin for FileFilterBuilder<'a>

§

impl<'a> UnwindSafe for FileFilterBuilder<'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.