Skip to main content

FileRequest

Struct FileRequest 

Source
#[non_exhaustive]
pub struct FileRequest { pub kind: ChooseKind, pub title: String, pub directory: Option<PathBuf>, pub purpose: Option<String>, pub force_directory: bool, pub file_name: Option<String>, pub filters: Vec<FileFilter>, pub confirm_overwrite: bool, pub group_files: bool, pub choices: Vec<FileChoice>, }
Expand description

What a choice asks for. Built with its constructors (FileRequest::open and the others) and their builders: a field added later breaks nobody.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§kind: ChooseKind§title: String

The chooser’s title.

§directory: Option<PathBuf>

Where it starts (the last recent place, else home, by default). With a purpose, only until that purpose has a last folder, unless force_directory said otherwise.

§purpose: Option<String>

The key the last folder is remembered under. See FileRequest::purpose.

§force_directory: bool

directory wins over the purpose’s last folder. See FileRequest::force_directory.

§file_name: Option<String>

The name proposed when saving.

§filters: Vec<FileFilter>§confirm_overwrite: bool

Saving: the in-app picker asks before replacing an existing file (on by default). See FileRequest::confirm_overwrite.

§group_files: bool

Opening files, the application’s groupings apply (on by default). See FileRequest::ungrouped.

§choices: Vec<FileChoice>

The application’s options, shown beside the in-app picker’s buttons. See FileRequest::choice.

Implementations§

Source§

impl FileRequest

Source

pub fn open(title: &str) -> Self

One existing file.

Source

pub fn open_many(title: &str) -> Self

Existing files.

Source

pub fn save(title: &str, name: &str) -> Self

A file to write, name proposed.

Source

pub fn folder(title: &str) -> Self

A folder.

Source

pub fn directory(self, dir: impl Into<PathBuf>) -> Self

Source

pub fn purpose(self, key: &str) -> Self

The choice’s purpose: its last folder is remembered under this key, so an import and an export do not share one (Windows’ SetClientGuid, the identifier of a macOS panel). The next choice of that purpose starts there: directory is then the first-time default (Windows’ SetDefaultFolder), and the start when the last folder is gone, before home. Recent places stay global, and a purpose does not start in them. Without a purpose nothing is remembered per choice and directory always wins.

Source

pub fn force_directory(self, dir: impl Into<PathBuf>) -> Self

Always starts in dir (Windows’ SetFolder), over the purpose’s last folder, which the choice still updates: for a request that names the folder that matters this time, as a document’s own. When dir is gone, the last folder, then home.

Source

pub fn file_name(self, name: &str) -> Self

Source

pub fn filter(self, name: &str, extensions: &[&str]) -> Self

Adds a filter (the first is the one shown first).

Source

pub fn confirm_overwrite(self, ask: bool) -> Self

Whether the in-app picker asks before replacing an existing file (on by default, as Windows’ FOS_OVERWRITEPROMPT and GTK 4): off for an application that asks itself. It holds for the in-app picker only: the system’s choosers ask on their own, and rfd has no way to tell them not to.

Source

pub fn ungrouped(self) -> Self

Every file is an entry of its own and a choice gives no groups, whatever the application’s groupings (groups): for a choice that is after a sidecar as much as a RAW. Saving and choosing a folder never group: a name to save under must see every file it could replace.

Source

pub fn choice( self, id: &str, label: &str, options: &[(&str, &str)], default: &str, ) -> Self

An option of the application’s, a combo box offering options ((id, label)) and starting on default: the in-app picker shows it beside its buttons, and the choice gives back the value picked (chosen_choices), as Windows’ customize interface, macOS’s accessory view and the desktop portal’s choices do; an import’s “Only new photos”, an export’s format. A request with choices opens the in-app picker even where the system’s chooser is used: rfd cannot show them.

Source

pub fn check(self, id: &str, label: &str, default: bool) -> Self

An option of the application’s as a check box, on or off at first; its value is "true" or "false". See FileRequest::choice.

Source

pub fn choice_defaults(&self) -> ChoiceValues

Each choice with the value it starts with.

Source

pub fn choice_values( &self, values: &ChoiceValues, ) -> Result<ChoiceValues, String>

values over the defaults, each checked: an unknown id or a value its choice cannot take is refused.

Source

pub fn to_json(&self) -> Json

Source

pub fn from_json(json: &Json) -> Result<FileRequest, String>

Trait Implementations§

Source§

impl Clone for FileRequest

Source§

fn clone(&self) -> FileRequest

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FileRequest

Source§

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

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

impl<'de> Deserialize<'de> for FileRequest

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for FileRequest

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for FileRequest

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for FileRequest

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,