Skip to main content

BatchStore

Trait BatchStore 

Source
pub trait BatchStore {
    type Error: Error;

    // Required methods
    fn get(
        &self,
        id: &BatchId,
    ) -> impl Future<Output = Result<Option<Batch>, Self::Error>> + Send;
    fn put(
        &self,
        batch: Batch,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send;
    fn remove(
        &self,
        id: &BatchId,
    ) -> impl Future<Output = Result<bool, Self::Error>> + Send;
    fn contains(
        &self,
        id: &BatchId,
    ) -> impl Future<Output = Result<bool, Self::Error>> + Send;
    fn context(
        &self,
    ) -> impl Future<Output = Result<PostageContext, Self::Error>> + Send;
    fn set_context(
        &self,
        state: PostageContext,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send;
    fn batch_ids(
        &self,
    ) -> impl Future<Output = Result<Vec<BatchId>, Self::Error>> + Send;
    fn count(&self) -> impl Future<Output = Result<usize, Self::Error>> + Send;
}
Available on crate feature std only.
Expand description

A trait for storing and retrieving batches.

Implementations may persist batches in memory, on disk, or retrieve them from a remote source such as a blockchain node.

§Async Design

This trait uses async methods to support both local (fast) and remote (potentially slow) storage backends without blocking.

Required Associated Types§

Source

type Error: Error

The error type returned by store operations.

Required Methods§

Source

fn get( &self, id: &BatchId, ) -> impl Future<Output = Result<Option<Batch>, Self::Error>> + Send

Retrieves a batch by its ID.

Returns None if the batch doesn’t exist.

Source

fn put( &self, batch: Batch, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Stores or updates a batch.

Source

fn remove( &self, id: &BatchId, ) -> impl Future<Output = Result<bool, Self::Error>> + Send

Removes a batch from the store.

Returns true if the batch existed and was removed.

Source

fn contains( &self, id: &BatchId, ) -> impl Future<Output = Result<bool, Self::Error>> + Send

Checks if a batch exists in the store.

Source

fn context( &self, ) -> impl Future<Output = Result<PostageContext, Self::Error>> + Send

Returns the current postage context.

Source

fn set_context( &self, state: PostageContext, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Updates the postage context.

Source

fn batch_ids( &self, ) -> impl Future<Output = Result<Vec<BatchId>, Self::Error>> + Send

Returns all batch IDs in the store.

Source

fn count(&self) -> impl Future<Output = Result<usize, Self::Error>> + Send

Returns the number of batches in the store.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§