Trait filesystem::FileSystem
[−]
[src]
pub trait FileSystem { fn current_dir(&self) -> Result<PathBuf>; fn set_current_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>; fn is_dir<P: AsRef<Path>>(&self, path: P) -> bool; fn is_file<P: AsRef<Path>>(&self, path: P) -> bool; fn create_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>; fn create_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<()>; fn remove_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>; fn remove_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<()>; fn create_file<P, B>(&self, path: P, buf: B) -> Result<()>
where
P: AsRef<Path>,
B: AsRef<[u8]>; fn write_file<P, B>(&self, path: P, buf: B) -> Result<()>
where
P: AsRef<Path>,
B: AsRef<[u8]>; fn read_file<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>>; fn readonly<P: AsRef<Path>>(&self, path: P) -> Result<bool>; fn set_readonly<P: AsRef<Path>>(
&self,
path: P,
readonly: bool
) -> Result<()>; }
Provides standard file system operations.
Required Methods
fn current_dir(&self) -> Result<PathBuf>
Returns the current working directory.
This is based on std::env::current_dir
.
fn set_current_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>
Updates the current working directory.
This is based on std::env::set_current_dir
.
fn is_dir<P: AsRef<Path>>(&self, path: P) -> bool
Determines whether the path exists and points to a directory.
fn is_file<P: AsRef<Path>>(&self, path: P) -> bool
Determines whether the path exists and points to a file.
fn create_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>
Creates a new directory.
This is based on std::fs::create_dir
.
fn create_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<()>
Recursively creates a directory and any missing parents.
This is based on [std::fs::create_dir
].
fn remove_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>
Removes an empty directory.
This is based on std::fs::remove_dir
.
fn remove_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<()>
Removes a directory and any child files or directories.
This is based on std::fs::remove_dir_all
.
fn create_file<P, B>(&self, path: P, buf: B) -> Result<()> where
P: AsRef<Path>,
B: AsRef<[u8]>,
P: AsRef<Path>,
B: AsRef<[u8]>,
Writes buf
to a new file at path
.
Errors
- A file or directory already exists at
path
. - The parent directory of
path
does not exist. - Current user has insufficient permissions.
fn write_file<P, B>(&self, path: P, buf: B) -> Result<()> where
P: AsRef<Path>,
B: AsRef<[u8]>,
P: AsRef<Path>,
B: AsRef<[u8]>,
Writes buf
to a new or existing file at buf
.
This will overwrite any contents that already exist.
Errors
- The parent directory of
path
does not exist. - Current user has insufficient permissions.
fn read_file<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>>
Returns the contents of path
.
Errors
path
does not exist.path
is a directory.Current user has insufficient permissions.
fn readonly<P: AsRef<Path>>(&self, path: P) -> Result<bool>
Returns true
if path
is a readonly file.
Errors
path
does not exist.Current user has insufficient permissions.
fn set_readonly<P: AsRef<Path>>(&self, path: P, readonly: bool) -> Result<()>
Sets or unsets the readonly flag of path
.
Errors
path
does not exist.Current user has insufficient permissions.
Implementors
impl FileSystem for FakeFileSystem
impl FileSystem for OsFileSystem