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§
sourcefn set_pwd_inner(&self, path: &Path) -> Result<(), Error>
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
.
sourcefn get_pwd(&self) -> Result<PathBuf, Error>
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
.
sourcefn open_inner(&self, path: &Path) -> Result<File<Self>, Error>
fn open_inner(&self, path: &Path) -> Result<File<Self>, Error>
Opens an exisitent file
This function corresponds to std::fs::File::open
.
sourcefn create_inner(&self, path: &Path) -> Result<File<Self>, Error>
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
.
sourcefn open_with_options_inner(
&self,
path: &Path,
options: OpenOptions
) -> Result<File<Self>, Error>
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
.
sourcefn read_inner(&self, file: &FileInner, buf: &mut [u8]) -> Result<usize, Error>
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
.
sourcefn read_to_end_inner(
&self,
file: &mut FileInner,
buf: &mut Vec<u8>
) -> Result<usize, Error>
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
.
sourcefn read_to_string_inner(
&self,
file: &mut FileInner,
buf: &mut String
) -> Result<usize, Error>
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
.
sourcefn write_inner(&self, file: &mut FileInner, buf: &[u8]) -> Result<usize, Error>
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
.
sourcefn write_all_inner(&self, file: &mut FileInner, buf: &[u8]) -> Result<(), Error>
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
.
sourcefn flush_inner(&self, file: &mut FileInner) -> Result<(), Error>
fn flush_inner(&self, file: &mut FileInner) -> Result<(), Error>
Flushes all writes of the file
This function corresponds to std::io::Write::flush
.
sourcefn metadata_inner(&self, file: &FileInner) -> Result<Metadata, Error>
fn metadata_inner(&self, file: &FileInner) -> Result<Metadata, Error>
Retrieves the metadata of the file
This function corresponds to std::fs::File::metadata
.
sourcefn seek_inner(&self, file: &mut FileInner, pos: SeekFrom) -> Result<u64, Error>
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
.
sourcefn create_dir_inner(&self, path: &Path) -> Result<(), Error>
fn create_dir_inner(&self, path: &Path) -> Result<(), Error>
Creates a directory
This function corresponds to std::fs::create_dir
.
sourcefn create_dir_all_inner(&self, path: &Path) -> Result<(), Error>
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
.
sourcefn close_inner(&self, file: FileInner) -> Result<(), Error>
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
.
sourcefn walkdir_inner(&self, path: &Path) -> WalkDir<Self>
fn walkdir_inner(&self, path: &Path) -> WalkDir<Self>
Creates a Walkdir
from a path
This function corresponds to walkdir::WalkDir::new
.
sourcefn into_walkdir_iterator(&self, walkdir: WalkDir<Self>) -> WalkdirIterator<Self> ⓘ
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
.
sourcefn walkdir_next_inner(
&self,
inner: &mut WalkdirIteratorInner
) -> Option<Result<DirEntry, Error>>
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
WalkDirIterator
and
corresponds therefore to std::iter::Iterator::next
.