Skip to main content

Storage

Trait Storage 

Source
pub trait Storage: Send + Sync {
    // Required methods
    fn read_range(&self, range: Range<u64>) -> BoxFuture<'_, Result<Bytes>>;
    fn write(&self, data: Bytes) -> BoxFuture<'_, Result<()>>;
    fn size(&self) -> BoxFuture<'_, Result<u64>>;
    fn write_multipart(&self) -> BoxFuture<'_, Result<Box<dyn MultipartWriter>>>;
}
Expand description

Async storage backend for reading and writing file data.

All methods return BoxFuture so the trait is object-safe (dyn Storage is valid).

§Extensibility

Implement this trait to plug in custom storage backends (e.g. a distributed file system, an HTTP range-request backend, etc.).

Required Methods§

Source

fn read_range(&self, range: Range<u64>) -> BoxFuture<'_, Result<Bytes>>

Reads the byte range range from the file.

Source

fn write(&self, data: Bytes) -> BoxFuture<'_, Result<()>>

Replaces the entire file content with data.

Source

fn size(&self) -> BoxFuture<'_, Result<u64>>

Returns the total size of the file in bytes.

Source

fn write_multipart(&self) -> BoxFuture<'_, Result<Box<dyn MultipartWriter>>>

Begins a streaming write that replaces the file’s contents.

The returned writer accepts successive byte chunks; the upload is committed once MultipartWriter::complete is awaited. This lets callers ship large payloads without materializing the whole file in memory.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§