Trait diskit::diskit::Diskit

source ·
pub trait Diskit: Clone + Default + 'static {
Show 19 methods // Required methods fn set_pwd_inner(&self, path: &Path) -> Result<(), Error>; fn get_pwd(&self) -> Result<PathBuf, Error>; fn open_inner(&self, path: &Path) -> Result<File<Self>, Error>; fn create_inner(&self, path: &Path) -> Result<File<Self>, Error>; fn open_with_options_inner( &self, path: &Path, options: OpenOptions ) -> Result<File<Self>, Error>; fn read_inner( &self, file: &FileInner, buf: &mut [u8] ) -> Result<usize, Error>; fn read_to_end_inner( &self, file: &mut FileInner, buf: &mut Vec<u8> ) -> Result<usize, Error>; fn read_to_string_inner( &self, file: &mut FileInner, buf: &mut String ) -> Result<usize, Error>; fn write_inner( &self, file: &mut FileInner, buf: &[u8] ) -> Result<usize, Error>; fn write_all_inner( &self, file: &mut FileInner, buf: &[u8] ) -> Result<(), Error>; fn flush_inner(&self, file: &mut FileInner) -> Result<(), Error>; fn metadata_inner(&self, file: &FileInner) -> Result<Metadata, Error>; fn seek_inner( &self, file: &mut FileInner, pos: SeekFrom ) -> Result<u64, Error>; fn create_dir_inner(&self, path: &Path) -> Result<(), Error>; fn create_dir_all_inner(&self, path: &Path) -> Result<(), Error>; fn close_inner(&self, file: FileInner) -> Result<(), Error>; fn walkdir_inner(&self, path: &Path) -> WalkDir<Self>; fn into_walkdir_iterator( &self, walkdir: WalkDir<Self> ) -> WalkdirIterator<Self> ; fn walkdir_next_inner( &self, inner: &mut WalkdirIteratorInner ) -> Option<Result<DirEntry, Error>>;
}
Expand description

Trait to intercept requests.

This trait handles the interception of disk requests. If you’re not implementing your own diskit you should mostly use the methods provided by the DiskitExt, io::Read and io::Write traits.

Many methods correspond directly to the normal ones from stdlib and should behave mostly the same, see therefore their documentation for the precise intended behavior.

Required Methods§

source

fn set_pwd_inner(&self, path: &Path) -> Result<(), Error>

Changes the current working directory

This sets the path relative to which relative paths are resolved. Notice that this function of course can also get a relative path.

It depends on the used diskit what path is the initial current working directory.

This function corresponds to std::env::set_current_dir.

source

fn get_pwd(&self) -> Result<PathBuf, Error>

Retrieves the current working directory

This gets the path relative to which relative paths are resolved.

It depends on the used diskit what path is the initial current working directory

This function corresponds to std::env::current_dir.

source

fn open_inner(&self, path: &Path) -> Result<File<Self>, Error>

Opens an exisitent file

This function corresponds to std::fs::File::open.

source

fn create_inner(&self, path: &Path) -> Result<File<Self>, Error>

Creates a new file or truncates it

This function corresponds to std::fs::File::create.

source

fn open_with_options_inner( &self, path: &Path, options: OpenOptions ) -> Result<File<Self>, Error>

Opens a file with custom options

This function corresponds to std::fs::OpenOptions::open.

source

fn read_inner(&self, file: &FileInner, buf: &mut [u8]) -> Result<usize, Error>

Reads as much as possible into the provided buffer

This function corresponds to std::io::Read::read.

source

fn read_to_end_inner( &self, file: &mut FileInner, buf: &mut Vec<u8> ) -> Result<usize, Error>

Reads the complete file into the provided buffer

This function corresponds to std::io::Read::read_to_end.

source

fn read_to_string_inner( &self, file: &mut FileInner, buf: &mut String ) -> Result<usize, Error>

Reads the complete file into the provided string

This function corresponds to std::io::Read::read_to_string.

source

fn write_inner(&self, file: &mut FileInner, buf: &[u8]) -> Result<usize, Error>

Writes as much as possible from the provided buffer

This function corresponds to std::io::Write::write.

source

fn write_all_inner(&self, file: &mut FileInner, buf: &[u8]) -> Result<(), Error>

Writes the complete provided buufer into the file

This function corresponds to std::io::Write::write_all.

source

fn flush_inner(&self, file: &mut FileInner) -> Result<(), Error>

Flushes all writes of the file

This function corresponds to std::io::Write::flush.

source

fn metadata_inner(&self, file: &FileInner) -> Result<Metadata, Error>

Retrieves the metadata of the file

This function corresponds to std::fs::File::metadata.

source

fn seek_inner(&self, file: &mut FileInner, pos: SeekFrom) -> Result<u64, Error>

Repositions the file’s cursor

This function corresponds to std::io::Seek::seek.

source

fn create_dir_inner(&self, path: &Path) -> Result<(), Error>

Creates a directory

This function corresponds to std::fs::create_dir.

source

fn create_dir_all_inner(&self, path: &Path) -> Result<(), Error>

Creates a directory and all above if necessary

This function corresponds to std::fs::create_dir_all.

source

fn close_inner(&self, file: FileInner) -> Result<(), Error>

Closes the file

This function manually closes the file. If this is not done the file will be automatically closed on drop, printing any error to stderr. The behavior of the stdlib is to quietly discard the error.

This function is not directly supported in the stdlib as far as I know. The best correspondence would be std::mem::drop.

source

fn walkdir_inner(&self, path: &Path) -> WalkDir<Self>

Creates a Walkdir from a path

This function corresponds to walkdir::WalkDir::new.

source

fn into_walkdir_iterator(&self, walkdir: WalkDir<Self>) -> WalkdirIterator<Self>

Converts a walkdir builder to an iterator

This function is used to provide the IntoIterator implementation of WalkDir and corresponds therefore to std::iter::IntoIterator::into_iter.

source

fn walkdir_next_inner( &self, inner: &mut WalkdirIteratorInner ) -> Option<Result<DirEntry, Error>>

Gets the next file in a WalkDir

This function is used to provide the Iterator implementation of WalkDirIteratorand corresponds therefore to std::iter::Iterator::next.

Object Safety§

This trait is not object safe.

Implementors§