pub struct FilePicker;Expand description
Frontend-agnostic file picker that delegates to the native platform dialog.
FilePicker has no state and is cheap to construct. All methods return
standard Future values that can be awaited from any async runtime,
including pollster::block_on for synchronous contexts.
§Examples
use loki_file_access::{FilePicker, PickOptions};
let picker = FilePicker::new();
let token = picker
.pick_file_to_open(PickOptions::default())
.await?;
if let Some(token) = token {
println!("Selected: {}", token.display_name());
}Implementations§
Source§impl FilePicker
impl FilePicker
Sourcepub async fn pick_file_to_open(
&self,
options: PickOptions,
) -> Result<Option<FileAccessToken>, PickerError>
pub async fn pick_file_to_open( &self, options: PickOptions, ) -> Result<Option<FileAccessToken>, PickerError>
Present a platform dialog for the user to select a single file.
Returns Ok(Some(token)) if the user selected a file, or Ok(None)
if the user cancelled the dialog. The multi field of options is
ignored — use pick_files_to_open for
multi-selection.
§Errors
Returns PickerError if the platform dialog could not be presented.
Sourcepub async fn pick_files_to_open(
&self,
options: PickOptions,
) -> Result<Vec<FileAccessToken>, PickerError>
pub async fn pick_files_to_open( &self, options: PickOptions, ) -> Result<Vec<FileAccessToken>, PickerError>
Present a platform dialog for the user to select multiple files.
Returns a (possibly empty) vector of tokens. An empty vector means
the user cancelled the dialog. The multi field of options is
forced to true.
§Errors
Returns PickerError if the platform dialog could not be presented.
Sourcepub async fn pick_file_to_save(
&self,
options: SaveOptions,
) -> Result<Option<FileAccessToken>, PickerError>
pub async fn pick_file_to_save( &self, options: SaveOptions, ) -> Result<Option<FileAccessToken>, PickerError>
Present a platform dialog for the user to choose a save location.
Returns Ok(Some(token)) if the user confirmed a save location, or
Ok(None) if the user cancelled.
§Platform notes
On WASM, this triggers a browser download via a Blob URL rather than presenting a traditional save dialog. The returned token wraps an in-memory buffer.
§Errors
Returns PickerError if the platform dialog could not be presented.
Trait Implementations§
Source§impl Clone for FilePicker
impl Clone for FilePicker
Source§fn clone(&self) -> FilePicker
fn clone(&self) -> FilePicker
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FilePicker
impl Debug for FilePicker
Source§impl Default for FilePicker
impl Default for FilePicker
Source§fn default() -> FilePicker
fn default() -> FilePicker
Auto Trait Implementations§
impl Freeze for FilePicker
impl RefUnwindSafe for FilePicker
impl Send for FilePicker
impl Sync for FilePicker
impl Unpin for FilePicker
impl UnsafeUnpin for FilePicker
impl UnwindSafe for FilePicker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.