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§
Sourcefn get<'a>(
&'a self,
path: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>, Error>> + Send + 'a>>
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.
Sourcefn put<'a>(
&'a self,
path: &'a str,
contents: Bytes,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>
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.
Sourcefn delete<'a>(
&'a self,
path: &'a str,
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'a>>
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.
Sourcefn exists<'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>>
Whether a file exists.
Provided Methods§
Sourcefn copy<'a>(
&'a self,
from: &'a str,
to: &'a str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>
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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".