Skip to main content

FileSpec

Struct FileSpec 

Source
pub struct FileSpec {
    pub name: &'static str,
    pub extensions: &'static [&'static str],
}
Expand description

A description of a filetype, for specifying allowed types in a file dialog.

§Windows

Each instance of this type is converted to a COMDLG_FILTERSPEC struct.

§macOS

These file types also apply to directories to define them as packages.

Fields§

§name: &'static str

A human readable name, describing this filetype.

This is used in the Windows file dialog, where the user can select from a dropdown the type of file they would like to choose.

This should not include the file extensions; they will be added automatically. For instance, if we are describing Word documents, the name would be “Word Document”, and the displayed string would be “Word Document (*.doc)”.

§extensions: &'static [&'static str]

The file extensions used by this file type.

This should not include the leading ‘.’.

Implementations§

Source§

impl FileSpec

Source

pub const TEXT: FileSpec

Source

pub const JPG: FileSpec

Source

pub const GIF: FileSpec

Source

pub const PNG: FileSpec

Source

pub const PDF: FileSpec

Source

pub const HTML: FileSpec

Source

pub const fn new( name: &'static str, extensions: &'static [&'static str], ) -> Self

Create a new FileSpec.

Examples found in repository?
examples/shello.rs (line 55)
47    fn command(&mut self, id: u32) {
48        match id {
49            0x100 => {
50                self.handle.close();
51                Application::global().quit()
52            }
53            0x101 => {
54                let options = FileDialogOptions::new().show_hidden().allowed_types(vec![
55                    FileSpec::new("Rust Files", &["rs", "toml"]),
56                    FileSpec::TEXT,
57                    FileSpec::JPG,
58                ]);
59                self.handle.open_file(options);
60            }
61            0x102 => {
62                let options = FileDialogOptions::new().show_hidden().allowed_types(vec![
63                    FileSpec::new("Rust Files", &["rs", "toml"]),
64                    FileSpec::TEXT,
65                    FileSpec::JPG,
66                ]);
67                self.handle.save_as(options);
68            }
69            _ => println!("unexpected id {id}"),
70        }
71    }

Trait Implementations§

Source§

impl Clone for FileSpec

Source§

fn clone(&self) -> FileSpec

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 Copy for FileSpec

Source§

impl Debug for FileSpec

Source§

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

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

impl Eq for FileSpec

Source§

impl PartialEq for FileSpec

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FileSpec

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> RoundFrom<T> for T

Source§

fn round_from(x: T) -> T

Performs the conversion.
Source§

impl<T, U> RoundInto<U> for T
where U: RoundFrom<T>,

Source§

fn round_into(self) -> U

Performs the conversion.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more