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§

Required Methods§

source

fn is_batch_full(&self, batch: &B) -> bool

Return true if it is not possible for another item to fit in the batch

source

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.

source

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

source

fn reset(&mut self)

Reset internal state from a batch being taken.

Implementors§

source§

impl<T, B, I> BatchLimiter<T, B> for SizeLimit<I>
where B: BatchData<T>, I: ItemBatchSize<T>,