Skip to main content

ReadStorage

Trait ReadStorage 

Source
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§

Source

fn read(&self, path: &Path) -> impl Future<Output = Result<Vec<u8>>>

Read the entire contents of a file as bytes. Mirrors std::fs::read.

Source

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.

Source

fn read_dir(&self, path: &Path) -> impl Future<Output = Result<Vec<DirEntry>>>

Return the entries in a directory (non-recursive). Mirrors std::fs::read_dir, but yields a Vec since async iterators are not yet stable.

Source

fn metadata(&self, path: &Path) -> impl Future<Output = Result<Metadata>>

Return metadata about the entry at path. Mirrors std::fs::metadata; follows symlinks.

Provided Methods§

Source

fn try_exists(&self, path: &Path) -> impl Future<Output = Result<bool>>

Returns Ok(true) if the path exists, Ok(false) if it does not, and Err(_) if the check itself failed. Mirrors std::fs::try_exists.

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.

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.

Source§

async fn read(&self, path: &Path) -> Result<Vec<u8>>

Source§

async fn read_to_string(&self, path: &Path) -> Result<String>

Source§

async fn read_dir(&self, path: &Path) -> Result<Vec<DirEntry>>

Source§

async fn metadata(&self, path: &Path) -> Result<Metadata>

Source§

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.

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.

Source§

async fn read(&self, path: &Path) -> Result<Vec<u8>>

Source§

async fn read_to_string(&self, path: &Path) -> Result<String>

Source§

async fn read_dir(&self, path: &Path) -> Result<Vec<DirEntry>>

Source§

async fn metadata(&self, path: &Path) -> Result<Metadata>

Source§

async fn try_exists(&self, path: &Path) -> Result<bool>

Implementors§