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§

Required Methods§

source

fn len(&self) -> usize

Returns the number of elements in the batch

source

fn take_batch(&mut self) -> Self::Batch

Returns the current batch, and resets any internal state

source

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

source

fn is_batch_full(&self) -> bool

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

source

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.

source

fn timeout(&self) -> Duration

Returns the maximum amount of time to wait for inputs to a single batch. The timer starts when the first item is received for a batch.

Provided Methods§

source

fn is_empty(&self) -> bool

Determines whether the batch is empty or not

Implementors§

source§

impl<T, L, B> BatchConfig<T> for BatchConfigParts<L, B>
where L: BatchLimiter<T, B>, B: BatchData<T>,

§

type ItemMetadata = <L as BatchLimiter<T, B>>::ItemMetadata

§

type Batch = <B as BatchData<T>>::Batch