Skip to main content

FileSystem

Trait FileSystem 

Source
pub trait FileSystem:
    Debug
    + Send
    + Sync {
    // Required methods
    fn metadata(&self) -> FileSystemMetadata;
    fn path_metadata(&self, path: &FsPath) -> FsResult<FileMetadata>;
    fn exists(&self, path: &FsPath) -> FsResult<bool>;
    fn list(
        &self,
        path: &FsPath,
        options: &ListOptions,
    ) -> FsResult<Box<dyn DirectoryStream>>;
    fn open_reader(
        &self,
        path: &FsPath,
        options: &ReadOptions,
    ) -> FsResult<Box<dyn FileReader>>;
    fn open_writer(
        &self,
        path: &FsPath,
        options: &WriteOptions,
    ) -> FsResult<Box<dyn FileWriter>>;
    fn create_dir(
        &self,
        path: &FsPath,
        options: &CreateDirOptions,
    ) -> FsResult<()>;
    fn delete(&self, path: &FsPath, options: &DeleteOptions) -> FsResult<()>;
    fn rename(
        &self,
        from: &FsPath,
        to: &FsPath,
        options: &RenameOptions,
    ) -> FsResult<()>;
    fn copy(
        &self,
        from: &FsPath,
        to: &FsPath,
        options: &CopyOptions,
    ) -> FsResult<CopyOutcome>;

    // Provided methods
    fn capabilities(&self) -> FileSystemCapabilities { ... }
    fn temp_resource_factory(&self) -> &dyn TempResourceFactory { ... }
}
Expand description

Provider-neutral filesystem interface.

Required Methods§

Source

fn metadata(&self) -> FileSystemMetadata

Gets metadata describing this filesystem instance.

§Returns

Filesystem metadata.

Source

fn path_metadata(&self, path: &FsPath) -> FsResult<FileMetadata>

Reads metadata for a path.

§Parameters
  • path: Resource path.
§Returns

Resource metadata.

§Errors

Returns crate::FsError when metadata cannot be read.

Source

fn exists(&self, path: &FsPath) -> FsResult<bool>

Checks whether a path exists.

§Parameters
  • path: Resource path.
§Returns

true when the resource exists.

§Errors

Returns crate::FsError for errors other than confirmed absence.

Source

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

Lists a directory, prefix, or collection.

§Parameters
  • path: Container path.
  • options: Listing options.
§Returns

Directory stream.

§Errors

Returns crate::FsError when listing cannot be started.

Source

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

Opens a readable resource.

§Parameters
  • path: Resource path.
  • options: Read options.
§Returns

Reader handle.

§Errors

Returns crate::FsError when the reader cannot be opened.

Source

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

Opens a writable resource.

§Parameters
  • path: Resource path.
  • options: Write options.
§Returns

Writer handle.

§Errors

Returns crate::FsError when the writer cannot be opened.

Source

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

Creates a directory, collection, or equivalent container.

§Parameters
  • path: Container path.
  • options: Creation options.
§Errors

Returns crate::FsError when the container cannot be created.

Source

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

Deletes a resource.

§Parameters
  • path: Resource path.
  • options: Delete options.
§Errors

Returns crate::FsError when deletion fails.

Source

fn rename( &self, from: &FsPath, to: &FsPath, options: &RenameOptions, ) -> FsResult<()>

Renames or moves a resource within this filesystem.

§Parameters
  • from: Source path.
  • to: Destination path.
  • options: Rename options.
§Errors

Returns crate::FsError when rename fails.

Source

fn copy( &self, from: &FsPath, to: &FsPath, options: &CopyOptions, ) -> FsResult<CopyOutcome>

Copies a resource within this filesystem.

§Parameters
  • from: Source path.
  • to: Destination path.
  • options: Copy options.
§Returns

Copy outcome.

§Errors

Returns crate::FsError when copy fails.

Provided Methods§

Source

fn capabilities(&self) -> FileSystemCapabilities

Gets capability hints for this filesystem.

§Returns

Static capability hints.

Source

fn temp_resource_factory(&self) -> &dyn TempResourceFactory

Gets the temporary resource factory for this filesystem instance.

If the specified filesystem does not provide its specific implementation, a default ManagedTempResourceFactory will be returned.

§Returns

Factory used to create temporary files and directories owned by this filesystem instance.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§