pub trait ReadStorage {
// Required methods
fn read(&self, path: &Path) -> impl Future<Output = Result<Vec<u8>>>;
fn read_to_string(
&self,
path: &Path,
) -> impl Future<Output = Result<String>>;
fn read_dir(
&self,
path: &Path,
) -> impl Future<Output = Result<Vec<DirEntry>>>;
fn metadata(&self, path: &Path) -> impl Future<Output = Result<Metadata>>;
// Provided method
fn try_exists(&self, path: &Path) -> impl Future<Output = Result<bool>> { ... }
}Expand description
The read half of an async filesystem backend: everything the traversal core needs, and nothing that can change a byte on disk.
This is the trait crate::graph is generic over. The split is not
decoration — it is what lets the read core 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
workspace, 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>>>
fn read(&self, path: &Path) -> impl Future<Output = Result<Vec<u8>>>
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>>
fn read_to_string(&self, path: &Path) -> impl Future<Output = Result<String>>
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 + ?Sized> ReadStorage for &S
A borrowed ReadStorage is itself a ReadStorage — so an owned backend
can be lent to something generic over S: ReadStorage (e.g. a temporary
Graph) without moving it or wrapping it in an
Arc the caller doesn’t otherwise need.
impl<S: ReadStorage + ?Sized> ReadStorage for &S
A borrowed ReadStorage is itself a ReadStorage — so an owned backend
can be lent to something generic over S: ReadStorage (e.g. a temporary
Graph) without moving it or wrapping it in an
Arc the caller doesn’t otherwise need.
Every member is forwarded explicitly. prov-store’s matching Storage
forwarding 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>>
async fn read_to_string(&self, path: &Path) -> Result<String>
async fn read_dir(&self, path: &Path) -> Result<Vec<DirEntry>>
async fn metadata(&self, path: &Path) -> Result<Metadata>
async fn try_exists(&self, path: &Path) -> Result<bool>
Source§impl<S: ReadStorage + ?Sized> ReadStorage for Arc<S>
An Arc<S> is itself a ReadStorage on the same terms as &S above — so
a backend shared across several owners (several open Workspaces, 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 + ?Sized> ReadStorage for Arc<S>
An Arc<S> is itself a ReadStorage on the same terms as &S above — so
a backend shared across several owners (several open Workspaces, 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.