pub trait ReadStorage {
// Required methods
fn read(&self, path: &Path) -> impl Future<Output = Result<Vec<u8>, Error>>;
fn read_to_string(
&self,
path: &Path,
) -> impl Future<Output = Result<String, Error>>;
fn read_dir(
&self,
path: &Path,
) -> impl Future<Output = Result<Vec<DirEntry>, Error>>;
fn metadata(
&self,
path: &Path,
) -> impl Future<Output = Result<Metadata, Error>>;
// Provided method
fn try_exists(
&self,
path: &Path,
) -> impl Future<Output = Result<bool, Error>> { ... }
}Expand description
The read half of an async filesystem backend: everything the traversal core needs, and nothing that can change a byte on disk.
The split from Storage is not decoration — it is what lets a tree be
depended on by a consumer that must not, and cannot, write: a language
server, a renderer, a browser viewer. A backend that implements only this
is a provably read-only view, checked by the compiler rather than by
review.
Each method mirrors the std::fs function of the same name.
try_exists has a default in terms of metadata.
Required Methods§
Sourcefn read(&self, path: &Path) -> impl Future<Output = Result<Vec<u8>, Error>>
fn read(&self, path: &Path) -> impl Future<Output = Result<Vec<u8>, Error>>
Read the entire contents of a file as bytes. Mirrors std::fs::read.
Sourcefn read_to_string(
&self,
path: &Path,
) -> impl Future<Output = Result<String, Error>>
fn read_to_string( &self, path: &Path, ) -> impl Future<Output = Result<String, Error>>
Read the entire contents of a file as a string. Mirrors
std::fs::read_to_string.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<S> ReadStorage for &Swhere
S: ReadStorage + ?Sized,
A borrowed ReadStorage is itself a ReadStorage — so an owned backend
can be lent to something generic over S: ReadStorage without moving it or
wrapping it in an Arc the caller doesn’t otherwise need.
impl<S> ReadStorage for &Swhere
S: ReadStorage + ?Sized,
A borrowed ReadStorage is itself a ReadStorage — so an owned backend
can be lent to something generic over S: ReadStorage without moving it or
wrapping it in an Arc the caller doesn’t otherwise need.
Every member is forwarded explicitly. The matching Storage forwarding
below does the same for the durability members, where leaving any to
inherit the trait’s defaults would silently downgrade a real backend’s
guarantees the moment it was borrowed.
async fn read(&self, path: &Path) -> Result<Vec<u8>, Error>
async fn read_to_string(&self, path: &Path) -> Result<String, Error>
async fn read_dir(&self, path: &Path) -> Result<Vec<DirEntry>, Error>
async fn metadata(&self, path: &Path) -> Result<Metadata, Error>
async fn try_exists(&self, path: &Path) -> Result<bool, Error>
Source§impl<S> ReadStorage for Arc<S>where
S: ReadStorage + ?Sized,
An Arc<S> is itself a ReadStorage on the same terms as &S above — so
a backend shared across several owners (several open handles, a
multi-tab web client) still carries its real capabilities through the
Arc, rather than an adapter that forgot to unwrap it silently degrading
to the pessimistic defaults.
impl<S> ReadStorage for Arc<S>where
S: ReadStorage + ?Sized,
An Arc<S> is itself a ReadStorage on the same terms as &S above — so
a backend shared across several owners (several open handles, a
multi-tab web client) still carries its real capabilities through the
Arc, rather than an adapter that forgot to unwrap it silently degrading
to the pessimistic defaults.
Arc<S> derefs to S exactly like &S does, so the same explicit,
every-member forwarding applies for the same reason: the trait’s defaults
must never be reached by accident.