pub trait Storage: Send + Sync {
// Required methods
fn put(
&self,
key: &str,
data: &[u8],
content_type: &str,
) -> Result<String, StorageError>;
fn get(&self, key: &str) -> Result<Vec<u8>, StorageError>;
fn delete(&self, key: &str) -> Result<(), StorageError>;
fn url(&self, key: &str) -> String;
// Provided method
fn put_stream(
&self,
key: &str,
reader: &mut dyn Read,
content_type: &str,
) -> Result<String, StorageError> { ... }
}storage-azure or storage-gcs or storage-local or storage-s3 only.Expand description
Backend-independent object storage.
Implement this trait to plug a custom backend (a database-backed store,
…) into the same handler code that already works against
LocalStorage, S3Storage, AzureBlobStorage and GcsStorage.
Required Methods§
Sourcefn put(
&self,
key: &str,
data: &[u8],
content_type: &str,
) -> Result<String, StorageError>
fn put( &self, key: &str, data: &[u8], content_type: &str, ) -> Result<String, StorageError>
Store data under key, overwriting any existing object at that key.
Returns the key that was stored (backends that normalize or namespace
keys may return a different string than the one passed in).
Provided Methods§
Sourcefn put_stream(
&self,
key: &str,
reader: &mut dyn Read,
content_type: &str,
) -> Result<String, StorageError>
fn put_stream( &self, key: &str, reader: &mut dyn Read, content_type: &str, ) -> Result<String, StorageError>
Store everything reader yields under key — for a body too large
to hold in memory, e.g. a streamed upload (Request::body read as a
stream, #31). LocalStorage writes as it reads and S3Storage
uploads in parts (S3 multipart upload), so memory stays at one part;
the default reads everything first and calls Storage::put.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".