Trait vector_stream::batcher::config::BatchConfig
source · pub trait BatchConfig<T> {
type ItemMetadata;
type Batch;
// Required methods
fn len(&self) -> usize;
fn take_batch(&mut self) -> Self::Batch;
fn push(&mut self, item: T, metadata: Self::ItemMetadata);
fn is_batch_full(&self) -> bool;
fn item_fits_in_batch(&self, item: &T) -> (bool, Self::ItemMetadata);
fn timeout(&self) -> Duration;
// Provided method
fn is_empty(&self) -> bool { ... }
}
Required Associated Types§
type ItemMetadata
type Batch
Required Methods§
sourcefn take_batch(&mut self) -> Self::Batch
fn take_batch(&mut self) -> Self::Batch
Returns the current batch, and resets any internal state
sourcefn push(&mut self, item: T, metadata: Self::ItemMetadata)
fn push(&mut self, item: T, metadata: Self::ItemMetadata)
Adds a single item to the batch, with the given metadata that was calculated by item_fits_in_batch
sourcefn is_batch_full(&self) -> bool
fn is_batch_full(&self) -> bool
Returns true if it is not possible for another item to fit in the batch
sourcefn item_fits_in_batch(&self, item: &T) -> (bool, Self::ItemMetadata)
fn item_fits_in_batch(&self, item: &T) -> (bool, Self::ItemMetadata)
It is safe to assume that is_batch_full
would return false
before this is called.
You can return arbitrary metadata for an item that will be given back when the item
is actually pushed onto the batch. This is useful if there is an expensive calculation
to determine the “size” of the item.