Skip to main content

PickRequest

Struct PickRequest 

pub struct PickRequest { /* private fields */ }
Expand description

A portal file-chooser request, built up and then send on a worker thread.

The per-app delta between what used to be nine hand-written copies of this module is exactly what this struct captures: a title, an accept label, a filter set, and a worker-thread name.

Implementations§

§

impl PickRequest

pub fn open(title: &str, accept_label: &str) -> PickRequest

A single-file open chooser.

pub fn open_multiple(title: &str, accept_label: &str) -> PickRequest

A multi-select open chooser: the user may pick arbitrarily many files at once and every local one comes back.

pub fn directory(title: &str, accept_label: &str) -> PickRequest

Pick one existing folder. Directory authority still comes from the desktop portal; callers should not invent a path or build a private filesystem browser.

pub fn save( title: &str, accept_label: &str, suggested_name: &str, ) -> PickRequest

A Save chooser, seeding the filename field with suggested_name.

pub fn max_contents_bytes(self, limit: usize) -> PickRequest

Bound the total contents returned across all chosen files. Oversized selections fail without reading their full contents into memory. Applies to send_contents, not path or descriptor requests. With no override, the host’s existing contents policy applies.

pub fn contents_byte_limit(&self) -> Option<usize>

The requested aggregate contents budget, when explicitly bounded.

pub fn thread_name(self, name: &str) -> PickRequest

Name the worker thread, so a stuck picker is identifiable in a backtrace or top -H. Pickers that run on a dedicated thread (the Windows dialogs) use it; the Unix portal’s D-Bus requests run on the shared app runtime instead.

pub fn filter(self, f: FileFilter) -> PickRequest

Add a file-type filter. Order is the dropdown order; the first is the default.

pub fn all_files(self) -> PickRequest

Append the “All files” escape hatch.

pub fn title(&self) -> &str

pub fn is_multiple(&self) -> bool

pub fn is_open(&self) -> bool

Whether this opens existing files (single or multi-select).

pub fn filter_names(&self) -> Vec<&str>

The filter dropdown labels, in order. Lets an app assert on the chooser it configured without opening one.

pub fn suggested_name(&self) -> Option<&str>

The filename this request seeds a Save dialog with, if it is one.

pub fn accept_label(&self) -> &str

The chooser’s accept-button label.

pub fn filters(&self) -> &[FileFilter]

The file-type filters, in dropdown order.

pub fn is_directory(&self) -> bool

Whether this chooses a folder rather than files.

pub fn kind(&self) -> &PickKind

The chooser kind this request opens.

pub fn worker_name(&self) -> &str

The name of the worker thread a native picker runs on, when it runs on one (see Self::thread_name).

pub fn send(self) -> Receiver<PortalOutcome>

Hand the request to the current host’s crate::FilePicker. The UI thread is never blocked: the native picker runs the D-Bus round-trip and the host dialog entirely on a worker. A multi-select request should go through send_multiple instead, so every pick is delivered.

pub fn send_scoped(self, scope: impl EffectGate) -> Receiver<PortalOutcome>

Retain the original admitted caller through the actual chooser. The caller is rechecked on a worker immediately before the host picker runs; an expired caller never reaches the chooser effect.

pub fn send_open_file(self) -> Receiver<OpenFileOutcome>

Open one selected regular file on the portal worker and deliver its descriptor to the UI. This is intentionally a separate outcome path so normal path-based open/save callers retain their existing API.

This is valid only for a single-file Open request. Calling it for Save or multi-select requests reports a normal failed outcome.

pub fn send_save_file(self) -> Receiver<OpenFileOutcome>

Save counterpart of send_open_file: the destination the user chose, created and open for writing. Android’s chooser creates a document with no path the app may write, so a Save there must come through here; hosts that answer Save with a path refuse it. Valid only for a Save request.

pub fn send_multiple(self) -> Receiver<MultiOutcome>

Multi-select counterpart of send.

pub fn send_contents(self) -> Receiver<ContentsOutcome>

Deliver the chosen files’ contents instead of paths, for callers that only read what the user picked. Works where no local path exists (a browser page). Open requests only; multi-select delivers every file.

pub fn send_save_contents(self, bytes: Vec<u8>) -> Receiver<SaveOutcome>

Save bytes where the user chooses. Save requests only. A browser page downloads them under the suggested name.

Trait Implementations§

§

impl Clone for PickRequest

§

fn clone(&self) -> PickRequest

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
§

impl Debug for PickRequest

§

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

Formats the value using the given formatter. Read more

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 + Send + Sync> ⓘ

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

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Fruit for T
where T: Send + Downcast,

§

impl<T> MaybeSendSync for T
where T: Send + Sync + ?Sized,

§

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

§

impl<T> WasmNotSendSync for T

§

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