Trait genfs::Fs
[−]
[src]
pub trait Fs { type Path: ?Sized; type PathOwned; type File: File<Error = Self::Error>; type Dir: Dir<Self::DirEntry, Self::Error>; type DirEntry: DirEntry<Path = Self::Path, Metadata = Self::Metadata, Error = Self::Error>; type Metadata; type Permissions; type Error; fn open(
&self,
path: &Self::Path,
options: &OpenOptions<Self::Permissions>
) -> Result<Self::File, Self::Error>; fn remove_file(&mut self, path: &Self::Path) -> Result<(), Self::Error>; fn metadata(&self, path: &Self::Path) -> Result<Self::Metadata, Self::Error>; fn symlink_metadata(
&self,
path: &Self::Path
) -> Result<Self::Metadata, Self::Error>; fn rename(
&mut self,
from: &Self::Path,
to: &Self::Path
) -> Result<(), Self::Error>; fn copy(
&mut self,
from: &Self::Path,
to: &Self::Path
) -> Result<u64, Self::Error>; fn hard_link(
&mut self,
src: &Self::Path,
dst: &Self::Path
) -> Result<(), Self::Error>; fn symlink(
&mut self,
src: &Self::Path,
dst: &Self::Path
) -> Result<(), Self::Error>; fn read_link(
&self,
path: &Self::Path
) -> Result<Self::PathOwned, Self::Error>; fn canonicalize(
&self,
path: &Self::Path
) -> Result<Self::PathOwned, Self::Error>; fn create_dir(
&mut self,
path: &Self::Path,
options: &DirOptions<Self::Permissions>
) -> Result<(), Self::Error>; fn remove_dir(&mut self, path: &Self::Path) -> Result<(), Self::Error>; fn remove_dir_all(&mut self, path: &Self::Path) -> Result<(), Self::Error>; fn read_dir(&self, path: &Self::Path) -> Result<Self::Dir, Self::Error>; fn set_permissions(
&mut self,
path: &Self::Path,
perm: Self::Permissions
) -> Result<(), Self::Error>; }
Filesystem manipulation operations.
This trait contains basic methods to manipulate the contents of the local filesystem. All methods in this module represent cross-platform filesystem operations.
Associated Types
type Path: ?Sized
The borrowed path slice that represents a relative or absolute path on the filesystem.
type PathOwned
The owned path that represents a relative or absolute path on the filesystem.
type File: File<Error = Self::Error>
The type that represents a file on the filesystem.
type Dir: Dir<Self::DirEntry, Self::Error>
The type that represents a directory on the filesystem.
type DirEntry: DirEntry<Path = Self::Path, Metadata = Self::Metadata, Error = Self::Error>
The type that represents an entry in a directory on the filesystem.
type Metadata
The type that represents the metadata on the filesystem.
type Permissions
The type that represents the permissions of a reader/writer on the filesystem.
type Error
The type that represents the set of all errors that can occur during reading or writing.
Required Methods
fn open(
&self,
path: &Self::Path,
options: &OpenOptions<Self::Permissions>
) -> Result<Self::File, Self::Error>
&self,
path: &Self::Path,
options: &OpenOptions<Self::Permissions>
) -> Result<Self::File, Self::Error>
Opens a file at path
with the options specified by options
.
Errors
This function will return an error under a number of different circumstances.
fn remove_file(&mut self, path: &Self::Path) -> Result<(), Self::Error>
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).
Errors
This function will return an error in the following situations, but is not limited to just these cases:
path
points to a directory.- The user lacks permissions to remove the file.
fn metadata(&self, path: &Self::Path) -> Result<Self::Metadata, Self::Error>
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.
Errors
This function will return an error in the following situations, but is not limited to just these cases:
- The user lacks permissions to perform
metadata
call onpath
. path
does not exist.
fn symlink_metadata(
&self,
path: &Self::Path
) -> Result<Self::Metadata, Self::Error>
&self,
path: &Self::Path
) -> Result<Self::Metadata, Self::Error>
Query the metadata about a file without following symlinks.
Errors
This function will return an error in the following situations, but is not limited to just these cases:
- The user lacks permissions to perform
metadata
call onpath
. path
does not exist.
fn rename(
&mut self,
from: &Self::Path,
to: &Self::Path
) -> Result<(), Self::Error>
&mut self,
from: &Self::Path,
to: &Self::Path
) -> Result<(), Self::Error>
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.
Errors
This function will return an error in the following situations, but is not limited to just these cases:
from
does not exist.- The user lacks permissions to view contents.
from
andto
are on separate filesystems.
fn copy(
&mut self,
from: &Self::Path,
to: &Self::Path
) -> Result<u64, Self::Error>
&mut self,
from: &Self::Path,
to: &Self::Path
) -> Result<u64, Self::Error>
Copies the contents of one file to another. This function will also copy the permission bits of the original file to the destination file.
This function will overwrite the contents of to
.
Note that if from
and to
both point to the same file, then the file
will likely get truncated by this operation.
On success, the total number of bytes copied is returned and it is
equal to the length of the to
file as reported by metadata
.
Errors
This function will return an error in the following situations, but is not limited to just these cases:
- The
from
path is not a file. - The
from
file does not exist. - The current process does not have the permission rights to access
from
or writeto
.
fn hard_link(
&mut self,
src: &Self::Path,
dst: &Self::Path
) -> Result<(), Self::Error>
&mut self,
src: &Self::Path,
dst: &Self::Path
) -> Result<(), Self::Error>
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.
Errors
This function will return an error in the following situations, but is not limited to just these cases:
- The
src
path is not a file or doesn't exist.
fn symlink(
&mut self,
src: &Self::Path,
dst: &Self::Path
) -> Result<(), Self::Error>
&mut self,
src: &Self::Path,
dst: &Self::Path
) -> Result<(), Self::Error>
Creates a new symbolic link on the filesystem.
The dst
path will be a symbolic link pointing to the src
path.
fn read_link(&self, path: &Self::Path) -> Result<Self::PathOwned, Self::Error>
Reads a symbolic link, returning the file that the link points to.
Errors
This function will return an error in the following situations, but is not limited to just these cases:
path
is not a symbolic link.path
does not exist.
fn canonicalize(
&self,
path: &Self::Path
) -> Result<Self::PathOwned, Self::Error>
&self,
path: &Self::Path
) -> Result<Self::PathOwned, Self::Error>
Returns the canonical form of a path with all intermediate components normalized and symbolic links resolved.
Errors
This function will return an error in the following situations, but is not limited to just these cases:
path
does not exist.- A component in path is not a directory.
fn create_dir(
&mut self,
path: &Self::Path,
options: &DirOptions<Self::Permissions>
) -> Result<(), Self::Error>
&mut self,
path: &Self::Path,
options: &DirOptions<Self::Permissions>
) -> Result<(), Self::Error>
Creates a new, empty directory at the provided path with the specified options.
Errors
This function will return an error in the following situations, but is not limited to just these cases:
- User lacks permissions to create directory at
path
. path
already exists, unless therecursive
options was set.
fn remove_dir(&mut self, path: &Self::Path) -> Result<(), Self::Error>
Removes an existing, empty directory.
Errors
This function will return an error in the following situations, but is not limited to just these cases:
- The user lacks permissions to remove the directory at the provided
path
. * The directory isn't empty.
fn remove_dir_all(&mut self, path: &Self::Path) -> Result<(), Self::Error>
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.
Errors
See Fs::remove_file
and Fs::remove_dir
.
fn read_dir(&self, path: &Self::Path) -> Result<Self::Dir, Self::Error>
Returns an iterator over the entries within a directory.
The iterator will yield instances of Result``<
DirEntry
>
.
New errors may be encountered after an iterator is initially
constructed.
Errors
This function will return an error in the following situations, but is not limited to just these cases:
- The provided
path
doesn't exist. - The process lacks permissions to view the contents.
- The
path
points at a non-directory file.
fn set_permissions(
&mut self,
path: &Self::Path,
perm: Self::Permissions
) -> Result<(), Self::Error>
&mut self,
path: &Self::Path,
perm: Self::Permissions
) -> Result<(), Self::Error>
Changes the permissions found on a file or a directory.
Errors
This function will return an error in the following situations, but is not limited to just these cases:
path
does not exist.- The user lacks the permission to change attributes of the file.