Trait vector_stream::batcher::limiter::BatchLimiter
source · pub trait BatchLimiter<T, B> {
type ItemMetadata;
// Required methods
fn is_batch_full(&self, batch: &B) -> bool;
fn item_fits_in_batch(
&self,
item: &T,
batch: &B,
) -> (bool, Self::ItemMetadata);
fn push_item(&mut self, metadata: Self::ItemMetadata);
fn reset(&mut self);
}
Required Associated Types§
type ItemMetadata
Required Methods§
sourcefn is_batch_full(&self, batch: &B) -> bool
fn is_batch_full(&self, batch: &B) -> bool
Return true if it is not possible for another item to fit in the batch
sourcefn item_fits_in_batch(&self, item: &T, batch: &B) -> (bool, Self::ItemMetadata)
fn item_fits_in_batch(&self, item: &T, batch: &B) -> (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.
sourcefn push_item(&mut self, metadata: Self::ItemMetadata)
fn push_item(&mut self, metadata: Self::ItemMetadata)
Add a single item to the batch using the metadata that was calculated by item_fits_in_batch