pub trait ReadableFileSystem: HasFileType + Sized {
type ReadDirPollerType: ReadDirPoller<Self>;
// Required methods
fn open<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Self::FileType, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self::FileType: ReadableFile,
Self: 'async_trait;
fn canonicalize<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<RelativePathBuf, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn metadata<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Metadata, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn read<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn read_dir<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<ReadDir<'life0, Self::ReadDirPollerType, Self>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn read_link<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<RelativePathBuf, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn read_to_string<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn symlink_metadata<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Metadata, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
}
Expand description
A readable filesystem
Required Associated Types§
type ReadDirPollerType: ReadDirPoller<Self>
Required Methods§
Sourcefn open<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Self::FileType, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self::FileType: ReadableFile,
Self: 'async_trait,
fn open<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Self::FileType, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self::FileType: ReadableFile,
Self: 'async_trait,
Equivalent to
async fn open(&self, path: impl PathType) -> Result<Self::FileType>
where
Self::FileType: ReadableFile;
Attempts to open a file in read-only mode.
See OpenOptions
for more details.
Sourcefn canonicalize<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<RelativePathBuf, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn canonicalize<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<RelativePathBuf, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Equivalent to
async fn canonicalize(&self, path: impl PathType) -> Result<PathBuf>;
Returns the canonical, absolute form of a path with all intermediate components normalized and symbolic links resolved.
This is an async version of std::fs::canonicalize
§Errors
This function will return an error in the following situations, but is not limited to just these cases:
path
does not exist.- A non-final component in path is not a directory.
Sourcefn metadata<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Metadata, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn metadata<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Metadata, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Equivalent to
async fn metadata(&self, path: impl PathType) -> Result<Metadata>;
Given a path, queries the file system to get information about a file, directory, etc.
This is an async version of std::fs::metadata
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.
Sourcefn read<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn read<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Equivalent to
async fn read(&self, path: impl PathType) -> Result<Vec<u8>>;
Reads the entire contents of a file into a bytes vector.
This is an async version of std::fs::read
This is a convenience function for using ReadableFileSystem::open
and tokio::io::AsyncReadExt::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()
.
§Errors
This function will return an error if path
does not already exist.
Other errors may also be returned according to OpenOptions::open
.
It will also return an error if it encounters while reading an error
of a kind other than ErrorKind::Interrupted
.
Sourcefn read_dir<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<ReadDir<'life0, Self::ReadDirPollerType, Self>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn read_dir<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<ReadDir<'life0, Self::ReadDirPollerType, Self>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Equivalent to
async fn read_dir(&self, path: impl PathType)
-> Result<ReadDir<Self::ReadDirPollerType, Self>>;
Returns a stream over the entries within a directory.
This is an async version of std::fs::read_dir
See ReadDir
for more details and examples.
Sourcefn read_link<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<RelativePathBuf, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn read_link<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<RelativePathBuf, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Equivalent to
async fn read_link(&self, path: impl PathType) -> Result<PathBuf>;
Reads a symbolic link, returning the file that the link points to.
Note: this MUST return an absolute path (i.e. relative to the filesystem root) even if the link was stored internally within the filesystem as a relative one.
This is an async version of std::fs::read_link
Sourcefn read_to_string<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn read_to_string<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Equivalent to
async fn read_to_string(&self, path: impl PathType) -> Result<String>;
Creates a future which will open a file for reading and read the entire contents into a string and return said string.
This is the async equivalent of std::fs::read_to_string
Sourcefn symlink_metadata<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Metadata, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn symlink_metadata<'life0, 'async_trait>(
&'life0 self,
path: impl PathType + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<Metadata, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Equivalent to
async fn symlink_metadata(&self, path: impl PathType) -> Result<Metadata>;
Queries the file system metadata for a path.
This is an async version of std::fs::symlink_metadata
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.