Trait io_providers::fs::Fs [−][src]
pub trait Fs { fn open<P: AsRef<Path>>(
&self,
path: P,
open_options: &OpenOptions
) -> Result<File>; fn copy<P: AsRef<Path>, Q: AsRef<Path>>(
&self,
from: P,
to: Q
) -> Result<u64>; fn create_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>; fn create_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<()>; fn hard_link<P: AsRef<Path>, Q: AsRef<Path>>(
&self,
src: P,
dst: Q
) -> Result<()>; fn metadata<P: AsRef<Path>>(&self, path: P) -> Result<Metadata>; fn read<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>>; fn read_dir<P: AsRef<Path>>(&self, path: P) -> Result<ReadDir>; fn read_link<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf>; fn read_to_string<P: AsRef<Path>>(&self, path: P) -> Result<String>; fn remove_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>; fn remove_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<()>; fn remove_file<P: AsRef<Path>>(&self, path: P) -> Result<()>; fn rename<P: AsRef<Path>, Q: AsRef<Path>>(
&self,
from: P,
to: Q
) -> Result<()>; fn set_permissions<P: AsRef<Path>>(
&self,
path: P,
perm: Permissions
) -> Result<()>; fn symlink_metadata<P: AsRef<Path>>(&self, path: P) -> Result<Metadata>; fn write<P: AsRef<Path>, C: AsRef<[u8]>>(
&self,
path: P,
contents: C
) -> Result<()>; }
Provides access to file I/O.
Required Methods
fn open<P: AsRef<Path>>(
&self,
path: P,
open_options: &OpenOptions
) -> Result<File>
&self,
path: P,
open_options: &OpenOptions
) -> Result<File>
Opens a file at path
with the options specified by open_options
.
See std::fs::OpenOptions for more information.
fn copy<P: AsRef<Path>, Q: AsRef<Path>>(&self, from: P, to: Q) -> Result<u64>
Copies the contents of one file to another. This function will also copy the permission bits of the original file to the destination file.
See std::fs::copy for more information.
fn create_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>
Creates a new, empty directory at the provided path.
See std::fs::create_dir for more information.
fn create_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<()>
Recursively create a directory and all of its parent components if they are missing.
See std::fs::create_dir_all for more information.
fn hard_link<P: AsRef<Path>, Q: AsRef<Path>>(
&self,
src: P,
dst: Q
) -> Result<()>
&self,
src: P,
dst: Q
) -> Result<()>
Creates a new hard link on the filesystem.
The dst
path will be a link pointing to the src
path. Note that systems often require
these two paths to both be located on the same filesystem.
See std::fs::hard_link for more information.
fn metadata<P: AsRef<Path>>(&self, path: P) -> Result<Metadata>
Given a path, query the file system to get information about a file, directory, etc.
This function will traverse symbolic links to query information about the destination file.
See std::fs::metadata for more information.
fn read<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>>
Read the entire contents of a file into a bytes vector.
This is a convenience function for using fs::File::open
and fs::read_to_end
with fewer imports and without an intermediate variable. It pre-allocates a
buffer based on the file size when available, so it is generally faster than
reading into a vector created with Vec::new()
.
See std::fs::read for more information.
fn read_dir<P: AsRef<Path>>(&self, path: P) -> Result<ReadDir>
Returns an iterator over the entries within a directory.
The iterator will yield instances of io::Result<fs::DirEntry]>
.
New errors may be encountered after an iterator is initially constructed.
See std::fs::read_dir for more information.
fn read_link<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf>
Reads a symbolic link, returning the file that the link points to.
See std::fs::read_link for more information.
fn read_to_string<P: AsRef<Path>>(&self, path: P) -> Result<String>
Read the entire contents of a file into a string.
This is a convenience function for using fs::File::open
and fs::read_to_string
with fewer imports and without an intermediate variable. It pre-allocates a
buffer based on the file size when available, so it is generally faster than
reading into a string created with String::new()
.
See std::fs::read_to_string for more information.
fn remove_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>
Removes an existing, empty directory.
See std::fs::remove_dir for more information.
fn remove_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<()>
Removes a directory at this path, after removing all its contents. Use carefully!
This function does not follow symbolic links and it will simply remove the symbolic link itself.
See std::fs::remove_dir_all for more information.
fn remove_file<P: AsRef<Path>>(&self, path: P) -> Result<()>
Removes a file from the filesystem.
Note that there is no guarantee that the file is immediately deleted (e.g. depending on platform, other open file descriptors may prevent immediate removal).
See std::fs::remove_file for more information.
fn rename<P: AsRef<Path>, Q: AsRef<Path>>(&self, from: P, to: Q) -> Result<()>
Rename a file or directory to a new name, replacing the original file if
to
already exists.
This will not work if the new name is on a different mount point.
See std::fs::rename for more information.
fn set_permissions<P: AsRef<Path>>(
&self,
path: P,
perm: Permissions
) -> Result<()>
&self,
path: P,
perm: Permissions
) -> Result<()>
Changes the permissions found on a file or a directory.
See std::fs::set_permissions for more information.
fn symlink_metadata<P: AsRef<Path>>(&self, path: P) -> Result<Metadata>
Query the metadata about a file without following symlinks.
See std::fs::symlink_metadata for more information.
fn write<P: AsRef<Path>, C: AsRef<[u8]>>(
&self,
path: P,
contents: C
) -> Result<()>
&self,
path: P,
contents: C
) -> Result<()>
Write a slice as the entire contents of a file.
This function will create a file if it does not exist, and will entirely replace its contents if it does.
This is a convenience function for using fs::File::create
and fs::write_all
with fewer imports.
See std::fs::write for more information.