Skip to main content

FileResource

Struct FileResource 

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

A filesystem path bound to the filesystem that owns it.

FileResource is the high-level resource object returned by FileSystems::resource and FileSystemRegistry::resource. It keeps path operations close to the resolved filesystem without making FsPath itself carry any backend state.

Implementations§

Source§

impl FileResource

Source

pub fn new(fs: Arc<dyn FileSystem>, path: FsPath) -> Self

Creates a new filesystem resource.

§Parameters
  • fs: Filesystem instance that owns the path.
  • path: Filesystem-local path.
§Returns

A resource bound to the supplied filesystem and path.

Source

pub fn fs(&self) -> &dyn FileSystem

Returns the filesystem that owns this resource.

§Returns

A shared reference to the owning filesystem.

Source

pub fn path(&self) -> &FsPath

Returns the filesystem-local path of this resource.

§Returns

A shared reference to the filesystem-local path.

Source

pub fn metadata(&self) -> FsResult<FileMetadata>

Reads metadata for this resource.

§Returns

File metadata for this resource.

§Errors

Returns an error when the owning filesystem cannot read metadata for the resource path.

Source

pub fn exists(&self) -> FsResult<bool>

Checks whether this resource exists.

§Returns

true when the resource exists.

§Errors

Returns an error when the owning filesystem cannot determine existence for the resource path.

Source

pub fn list(&self, options: &ListOptions) -> FsResult<Box<dyn DirectoryStream>>

Lists child entries under this resource.

§Parameters
  • options: Listing options.
§Returns

A directory stream for the resource path.

§Errors

Returns an error when the owning filesystem cannot open a directory stream for the resource path.

Source

pub fn open_reader( &self, options: &ReadOptions, ) -> FsResult<Box<dyn FileReader>>

Opens this resource for reading.

§Parameters
  • options: Read options.
§Returns

A file reader for the resource path.

§Errors

Returns an error when the owning filesystem cannot open the resource for reading.

Source

pub fn open_writer( &self, options: &WriteOptions, ) -> FsResult<Box<dyn FileWriter>>

Opens this resource for writing.

§Parameters
  • options: Write options.
§Returns

A file writer for the resource path.

§Errors

Returns an error when the owning filesystem cannot open the resource for writing.

Source

pub fn read_all(&self) -> FsResult<Vec<u8>>

Reads this resource into memory.

§Returns

The complete byte content of this resource.

§Errors

Returns an error when the owning filesystem cannot open or read the resource.

Source

pub fn write_all(&self, bytes: &[u8]) -> FsResult<WriteOutcome>

Writes all bytes to this resource.

§Parameters
  • bytes: Complete byte content to write.
§Returns

Write outcome reported by the owning filesystem.

§Errors

Returns an error when the owning filesystem cannot open, write, flush, or commit the resource.

Source

pub fn create_dir(&self, options: &CreateDirOptions) -> FsResult<()>

Creates this resource as a directory.

§Parameters
  • options: Directory creation options.
§Errors

Returns an error when the owning filesystem cannot create the directory.

Source

pub fn delete(&self, options: &DeleteOptions) -> FsResult<()>

Deletes this resource.

§Parameters
  • options: Delete options.
§Errors

Returns an error when the owning filesystem cannot delete the resource.

Source

pub fn rename_to( &self, target: &FsPath, options: &RenameOptions, ) -> FsResult<()>

Renames this resource to another filesystem-local path.

§Parameters
  • target: Target filesystem-local path.
  • options: Rename options.
§Errors

Returns an error when the owning filesystem cannot rename the resource.

Source

pub fn copy_to( &self, target: &FsPath, options: &CopyOptions, ) -> FsResult<CopyOutcome>

Copies this resource to another filesystem-local path.

§Parameters
  • target: Target filesystem-local path.
  • options: Copy options.
§Returns

Copy outcome reported by the owning filesystem.

§Errors

Returns an error when the owning filesystem cannot copy the resource.

Trait Implementations§

Source§

impl Clone for FileResource

Source§

fn clone(&self) -> FileResource

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 FileResource

Source§

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

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

Source§

fn into_value_default(self) -> T

Converts this argument into the default value.
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.