[][src]Struct multistream_batch::multi_buf_batch::MultiBufBatch

pub struct MultiBufBatch<K: Debug + Ord + Hash, I: Debug> { /* fields omitted */ }

Collects items into multiple batches based on stream key. A batch may become ready after collecting max_size number of items or until max_duration has elapsed since first item was appended to the batch.

Batch item buffers are cached and reused to avoid allocations.

This base implementation does not handle actual awaiting for batch duration timeout.

Implementations

impl<K, I> MultiBufBatch<K, I> where
    K: Debug + Ord + Hash + Clone,
    I: Debug
[src]

pub fn new(max_size: usize, max_duration: Duration) -> MultiBufBatch<K, I>[src]

Crates new instance with given maximum batch size (max_size) and maximum duration (max_duration) that batch can last since first item appended to it.

Panics if max_size == 0.

pub fn poll(&self) -> PollResult<K>[src]

Checks if batch has reached one of its limits.

Returns:

  • PollResult::Ready(K) - batch for stream key K has reached one of its limit and is ready to be consumed,
  • PollResult::NotReady(None) - batch is not ready yet and has no items appeded yet,
  • PollResult::NotReady(Some(duration)) - batch is not ready yet but it will be ready after time duration due to duration limit.

pub fn append(&mut self, key: K, item: I)[src]

Appends item to batch with given stream key.

It is an contract error to append batch that is ready according to self.poll().

Panics if batch has already reached its max_size limit.

pub fn outstanding(&self) -> impl Iterator<Item = &K>[src]

Lists keys of outstanding batches.

pub fn clear(&mut self, key: &K)[src]

Starts new batch dropping all buffered items.

pub fn drain(&mut self, key: &K) -> Option<Drain<I>>[src]

Consumes batch by draining items from internal buffer.

pub fn flush(&mut self) -> Vec<(K, Vec<I>)>[src]

Flushes all outstanding batches starting from oldest.

pub fn get(&self, key: &K) -> Option<&[I]>[src]

Returns slice of internal item buffer of given outstanding batch.

pub fn clear_cache(&mut self)[src]

Drops cached batch buffers.

pub fn stats(&self) -> Stats[src]

Provides usage statistics.

Trait Implementations

impl<K: Debug + Ord + Hash, I: Debug> Debug for MultiBufBatch<K, I>[src]

Auto Trait Implementations

impl<K, I> RefUnwindSafe for MultiBufBatch<K, I> where
    I: RefUnwindSafe,
    K: RefUnwindSafe

impl<K, I> Send for MultiBufBatch<K, I> where
    I: Send,
    K: Send

impl<K, I> Sync for MultiBufBatch<K, I> where
    I: Sync,
    K: Sync

impl<K, I> Unpin for MultiBufBatch<K, I> where
    I: Unpin,
    K: Unpin

impl<K, I> UnwindSafe for MultiBufBatch<K, I> where
    I: RefUnwindSafe + UnwindSafe,
    K: RefUnwindSafe + UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.