Skip to main content

Filesystem

Trait Filesystem 

Source
pub trait Filesystem:
    Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> &str;
    fn get<'a>(
        &'a self,
        path: &'a str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>, Error>> + Send + 'a>>;
    fn put<'a>(
        &'a self,
        path: &'a str,
        contents: Bytes,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>;
    fn delete<'a>(
        &'a self,
        path: &'a str,
    ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'a>>;
    fn exists<'a>(
        &'a self,
        path: &'a str,
    ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'a>>;
    fn metadata<'a>(
        &'a self,
        path: &'a str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Metadata>, Error>> + Send + 'a>>;
    fn list<'a>(
        &'a self,
        prefix: &'a str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Metadata>, Error>> + Send + 'a>>;

    // Provided methods
    fn copy<'a>(
        &'a self,
        from: &'a str,
        to: &'a str,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> { ... }
    fn rename<'a>(
        &'a self,
        from: &'a str,
        to: &'a str,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> { ... }
    fn url(&self, path: &str) -> Option<String> { ... }
}
Expand description

Where a driver keeps bytes.

One shape for every driver, for one reason: an application that writes uploads should not know whether they land on a disk, in S3, or in a test’s memory.

Paths are always /-separated and always relative, whatever the platform underneath. A driver that stores on disk translates; a driver that stores in a bucket does not have to.

Required Methods§

Source

fn name(&self) -> &str

A label for diagnostics — "local", "s3", "memory".

Source

fn get<'a>( &'a self, path: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>, Error>> + Send + 'a>>

Read a file. None if it is not there.

A missing file is not an error: “read it if it exists” is the common case, and making the caller distinguish absence from failure by parsing a message is how absence ends up being treated as an outage.

Source

fn put<'a>( &'a self, path: &'a str, contents: Bytes, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>

Write a file, creating any directories it needs and replacing what was there.

Source

fn delete<'a>( &'a self, path: &'a str, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'a>>

Delete a file. true if it was there.

Source

fn exists<'a>( &'a self, path: &'a str, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'a>>

Whether a file exists.

Source

fn metadata<'a>( &'a self, path: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<Metadata>, Error>> + Send + 'a>>

A file’s metadata, or None.

Source

fn list<'a>( &'a self, prefix: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Metadata>, Error>> + Send + 'a>>

Every file directly under prefix, not recursing.

"" lists the root.

Provided Methods§

Source

fn copy<'a>( &'a self, from: &'a str, to: &'a str, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>

Copy a file.

Provided as read-then-write, which every driver can do. Override it where the backend can copy server-side — S3 can, and doing so avoids pulling the object through this process.

Source

fn rename<'a>( &'a self, from: &'a str, to: &'a str, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>

Move a file.

Source

fn url(&self, path: &str) -> Option<String>

A URL a browser can fetch, if this driver has one.

None for a driver with no public face — a local disk behind an application is not reachable by URL, and pretending otherwise produces a link that 404s.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§