Skip to main content

Backend

Trait Backend 

Source
pub trait Backend:
    Debug
    + Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> &'static str;
    fn put_object<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        id: &'life1 ObjectId,
        metadata: &'life2 Metadata,
        stream: ClientStream,
        access_time: Timestamp,
    ) -> Pin<Box<dyn Future<Output = Result<PutResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn get_object<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 ObjectId,
        access_time: Timestamp,
        range: Option<ByteRange>,
    ) -> Pin<Box<dyn Future<Output = Result<GetResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn set_expiry<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 ObjectId,
        expire_at: Timestamp,
        access_time: Timestamp,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn delete_object<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 ObjectId,
        access_time: Timestamp,
    ) -> Pin<Box<dyn Future<Output = Result<DeleteResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn get_metadata<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 ObjectId,
        access_time: Timestamp,
    ) -> Pin<Box<dyn Future<Output = Result<MetadataResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn join<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn as_multipart_upload_backend(&self) -> Result<&dyn MultipartUploadBackend> { ... }
    fn create_upload_session<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        id: &'life1 ObjectId,
        metadata: &'life2 Metadata,
        total_length: NonZeroU64,
    ) -> Pin<Box<dyn Future<Output = Result<Option<BackendToken>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn put_chunk<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        id: &'life1 ObjectId,
        token: &'life2 BackendToken,
        offset: u64,
        content_length: u64,
        stream: ClientStream,
    ) -> Pin<Box<dyn Future<Output = Result<UploadProgress>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn upload_offset<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        id: &'life1 ObjectId,
        token: &'life2 BackendToken,
    ) -> Pin<Box<dyn Future<Output = Result<UploadProgress>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn cancel_upload<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        id: &'life1 ObjectId,
        token: &'life2 BackendToken,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Trait implemented by all storage backends.

Object operations take access_time, the timestamp of the caller’s operation. Use it to decide whether an object or redirect has expired, so all steps of an operation use the same time, including retries and calls to other backends. An object is expired when its deadline is strictly earlier than access_time. Writes preserve the creation time and deadline in the supplied metadata.

Required Methods§

Source

fn name(&self) -> &'static str

The backend name, used for diagnostics.

Source

fn put_object<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 ObjectId, metadata: &'life2 Metadata, stream: ClientStream, access_time: Timestamp, ) -> Pin<Box<dyn Future<Output = Result<PutResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Stores an object at the given path with the given metadata.

Source

fn get_object<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ObjectId, access_time: Timestamp, range: Option<ByteRange>, ) -> Pin<Box<dyn Future<Output = Result<GetResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves (part of) an object at the given path, returning its metadata, a description of the part being returned, and the payload.

Source

fn set_expiry<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ObjectId, expire_at: Timestamp, access_time: Timestamp, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Extends the deadline of an existing object with expiration policy.

This only changes the stored deadline: the expiration policy, duration, payload, and all other metadata remain unchanged.

Returns true when the deadline was extended or was already at least as late as expire_at. Returns false when the object is absent, expired, manually expired, or changed concurrently.

Source

fn delete_object<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ObjectId, access_time: Timestamp, ) -> Pin<Box<dyn Future<Output = Result<DeleteResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Deletes the object at the given path.

Provided Methods§

Source

fn get_metadata<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ObjectId, access_time: Timestamp, ) -> Pin<Box<dyn Future<Output = Result<MetadataResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves only the metadata for an object, without the payload.

Source

fn join<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Waits for any outstanding background operations to complete before shutdown.

The default implementation is a no-op. Backends that spawn background tasks (such as TieredStorage) should override this to wait for those tasks to complete.

Source

fn as_multipart_upload_backend(&self) -> Result<&dyn MultipartUploadBackend>

Borrows this backend as a MultipartUploadBackend if supported.

The default returns an ErrorKind::Unsupported. Backends that implement MultipartUploadBackend should override this to return Ok(self).

Source

fn create_upload_session<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 ObjectId, metadata: &'life2 Metadata, total_length: NonZeroU64, ) -> Pin<Box<dyn Future<Output = Result<Option<BackendToken>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Creates a resumable upload session for the object at id.

Object metadata and its total length are declared upfront and cannot be mutated during the upload.

The returned string is opaque backend-defined state. StorageService protects it before exposing the session token outside the service layer.

Returns Ok(None) when this backend cannot store the described object resumably. Declining is a routine outcome rather than an error, and the default implementation declines.

§Errors

Returns an error only when the backend supports resumable uploads but failed to open the session.

Source

fn put_chunk<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 ObjectId, token: &'life2 BackendToken, offset: u64, content_length: u64, stream: ClientStream, ) -> Pin<Box<dyn Future<Output = Result<UploadProgress>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Writes a chunk of content_length bytes at offset into an open session.

A backend may acknowledge fewer bytes than the chunk supplied, for example by persisting only an aligned prefix. Callers must continue from the authoritative offset in the returned UploadProgress, or query Self::upload_offset after an ambiguous failure. A backend may or may not accept a replay starting before its persisted offset.

UploadProgress::Complete means the upload is terminal and the object is available through this backend’s normal read methods. A backend that composes another backend must finish its own publication work before returning that outcome.

A content_length of zero is valid. It writes nothing and reports the offset the backend holds.

Returns ErrorKind::UnknownUploadSession when token does not identify an open session, and ErrorKind::ChunkExceedsUploadLength when the chunk would exceed the total length declared when the session was created.

Source

fn upload_offset<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 ObjectId, token: &'life2 BackendToken, ) -> Pin<Box<dyn Future<Output = Result<UploadProgress>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Reports how far the session has progressed.

This can return UploadProgress::Complete repeatedly after the final chunk, including when its original response was lost. A composed backend may finish pending idempotent publication work before returning that terminal outcome.

Returns ErrorKind::UnknownUploadSession when token does not identify a known session.

Source

fn cancel_upload<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 ObjectId, token: &'life2 BackendToken, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Cancels an upload session, discarding whatever was uploaded.

Returns ErrorKind::UnknownUploadSession when token does not identify an open session.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§