pub trait BatchStore {
type Error: Error;
// Required methods
fn get(&self, id: &BatchId) -> Result<Option<Batch>, Self::Error>;
fn put(&self, batch: Batch) -> Result<(), Self::Error>;
fn remove(&self, id: &BatchId) -> Result<bool, Self::Error>;
fn contains(&self, id: &BatchId) -> Result<bool, Self::Error>;
fn context(&self) -> Result<PostageContext, Self::Error>;
fn set_context(&self, state: PostageContext) -> Result<(), Self::Error>;
fn batch_ids(&self) -> Result<Vec<BatchId>, Self::Error>;
fn count(&self) -> Result<usize, Self::Error>;
}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.
§Synchronous Design
The methods are synchronous. The known backends (in memory, redb) are
themselves synchronous, so there is no genuinely async work to drive here;
any async behaviour belongs at the true edges (a gRPC service, an FFI
boundary) where it is added by the edge, not by the store. Keeping the core
synchronous avoids colouring every caller with async, keeps the futures
Send-free on the wasm path, and makes this trait naturally object-safe (it
has an associated Error and no generic methods), a property the previous
async-in-trait shape did not have.
Required Associated Types§
Required Methods§
Sourcefn get(&self, id: &BatchId) -> Result<Option<Batch>, Self::Error>
fn get(&self, id: &BatchId) -> Result<Option<Batch>, Self::Error>
Retrieves a batch by its ID.
Returns None if the batch doesn’t exist.
Sourcefn remove(&self, id: &BatchId) -> Result<bool, Self::Error>
fn remove(&self, id: &BatchId) -> Result<bool, Self::Error>
Removes a batch from the store.
Returns true if the batch existed and was removed.
Sourcefn contains(&self, id: &BatchId) -> Result<bool, Self::Error>
fn contains(&self, id: &BatchId) -> Result<bool, Self::Error>
Checks if a batch exists in the store.
Sourcefn context(&self) -> Result<PostageContext, Self::Error>
fn context(&self) -> Result<PostageContext, Self::Error>
Returns the current postage context.
Sourcefn set_context(&self, state: PostageContext) -> Result<(), Self::Error>
fn set_context(&self, state: PostageContext) -> Result<(), Self::Error>
Updates the postage context.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".