Skip to main content

FileSystem

Trait FileSystem 

Source
pub trait FileSystem {
    type File: Read;

    // Required methods
    fn metadata(&self, path: &Utf8Path) -> Result<FileSystemMetadata>;
    fn read_dir(&self, path: &Utf8Path) -> Result<Vec<String>>;
    fn open(&self, path: &Utf8Path) -> Result<Self::File>;
}
Expand description

File system operations needed by crate::Encoder to encode a NAR file.

crate::Encoder will call this trait’s methods only with paths that are:

  • The archive’s root (given to the crate::Encoder’s constructor), or
  • Constructed by appending Self::read_dir iterator’s items to the archive’s root to descend into directories

§Consistency

Implementation is responsible for returning a consistent view of the filesystem.

The reader returned by Self::open must read exactly the number of bytes that was declared in its corresponding Self::metadata. In case of a mismatch, crate::Encoder will return an error to avoid creating an invalid NAR file.

Required Associated Types§

Source

type File: Read

Reader returned by Self::open

Required Methods§

Source

fn metadata(&self, path: &Utf8Path) -> Result<FileSystemMetadata>

Return type of a filesystem object.

§Errors

May return an I/O error.

Implementation should return an error (or avoid listing that object in Self::read_dir) if the object is not one of the types enumerated in FileSystemMetadata.

Source

fn read_dir(&self, path: &Utf8Path) -> Result<Vec<String>>

Iterate over entry names of a directory at the given path.

crate::Encoder will call this method only on paths, for which Self::metadata returned FileSystemMetadata::Directory.

§Errors

May return an I/O error

Source

fn open(&self, path: &Utf8Path) -> Result<Self::File>

Open a file at the given path, return its size in bytes and a Self::File reader

crate::Encoder will call this method only on paths for which Self::metadata returned FileSystemMetadata::File.

§Errors

May return an I/O error

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§