Skip to main content

ReadStorage

Trait ReadStorage 

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

Source

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.

Source

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.

Source

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

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, Error>>

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, Error>>

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 for &S
where 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.

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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.

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>, Error>

Source§

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

Source§

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

Source§

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

Source§

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

Implementors§