MultiBufBatch

Struct MultiBufBatch 

Source
pub struct MultiBufBatch<K: Debug + Ord + Hash, I: Debug> { /* private fields */ }
Expand description

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§

Source§

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

Source

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

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.

Source

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

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.
Source

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

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.

Source

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

Lists keys of outstanding batches.

Source

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

Starts new batch dropping all buffered items.

Source

pub fn drain(&mut self, key: &K) -> Option<Drain<'_, I>>

Consumes batch by draining items from internal buffer.

Source

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

Flushes all outstanding batches starting from oldest.

Source

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

Returns slice of internal item buffer of given outstanding batch.

Source

pub fn clear_cache(&mut self)

Drops cached batch buffers.

Source

pub fn stats(&self) -> Stats

Provides usage statistics.

Trait Implementations§

Source§

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<K, I> UnwindSafe for MultiBufBatch<K, I>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.