Skip to main content

PickedFile

Struct PickedFile 

Source
pub struct PickedFile { /* private fields */ }
Expand description

One file or folder the user chose, to read and write.

Cheap to clone: a clone names the same file. See the module documentation for what it holds on each platform.

Implementations§

Source§

impl PickedFile

Source

pub const MAX_READ_BYTES: u64

The longest file PickedFile::read reads, in bytes. A longer one is FileError::TooLarge before anything is read.

Source

pub fn from_path(path: impl Into<String>) -> PickedFile

A file by its path, without a dialog. For a path the application already had, such as one it saved in its own storage last time.

Only where there are paths: a browser gives a page none, so there is nothing to make one from there.

Source

pub fn name(&self) -> &str

The file’s name, without any folder in front of it.

Source

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

The file’s absolute path, where there is one. Never in a browser.

Source

pub fn is_folder(&self) -> bool

Whether this is a folder.

For a path, the file system is asked the first time, which is one small call on the calling thread. A browser said so when it handed the file over.

Source

pub fn delivery(&self) -> Delivery

How the file reached the application. Always Delivery::Handle for a path.

Source

pub fn can_write_again(&self) -> bool

Whether a write changes this same file again: a Delivery::Handle that is not a folder. When it is false the next save is a “save as”.

Source

pub async fn read(&self) -> Result<Vec<u8>, FileError>

Reads the whole file.

Source

pub async fn write(&self, bytes: impl Into<Vec<u8>>) -> Result<(), FileError>

Replaces the file’s contents with bytes.

For a path the new contents go to a temporary file in the same folder, which is then renamed over the file, so the file is always either what it was or what was written. A browser does the same inside the File System Access API’s writable stream. On a Delivery::Download every write is a new download of bytes under the file’s name.

Source

pub async fn entries(&self) -> Result<Vec<PickedFile>, FileError>

What a folder holds directly, files and folders both, in name order for a path and in the browser’s order in a browser.

Source

pub async fn child( &self, name: &str, create: bool, ) -> Result<PickedFile, FileError>

The file or folder called name directly inside this folder. With create, a file of that name is made, empty, when there is none.

name is one name: one with a path separator in it, or . or .., is refused before anything is asked.

Trait Implementations§

Source§

impl Clone for PickedFile

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 Debug for PickedFile

Source§

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

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

impl Eq for PickedFile

Source§

impl PartialEq for PickedFile

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

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