pub struct DelayBuffer<T> { /* private fields */ }Expand description
A delay buffer that outputs items as they are pushed out by newer items.
This is equivalent to Apama’s rstream operator:
retain 1 select rstream adelays output by 1 item- When a new item arrives, the oldest item is output
Use cases:
- Compare current value with previous value
- Detect changes between consecutive aggregations
- Implement “previous” reference in expressions
§Example
let mut delay = DelayBuffer::new(1);
// First item: nothing output (buffer filling)
assert_eq!(delay.push(10), None);
// Second item: first item output
assert_eq!(delay.push(20), Some(10));
// Third item: second item output
assert_eq!(delay.push(30), Some(20));Implementations§
Source§impl<T: Clone> DelayBuffer<T>
impl<T: Clone> DelayBuffer<T>
Sourcepub fn new(delay: usize) -> Self
pub fn new(delay: usize) -> Self
Create a new delay buffer with specified delay count.
A delay of 1 means the previous item is output when a new item arrives.
Sourcepub fn push(&mut self, item: T) -> Option<T>
pub fn push(&mut self, item: T) -> Option<T>
Push a new item and potentially output a delayed item.
Returns Some(item) if there’s an item to output (buffer was full),
or None if the buffer is still filling up.
Sourcepub fn previous(&self) -> Option<&T>
pub fn previous(&self) -> Option<&T>
Get the previous item (one before current) without removing it.
Trait Implementations§
Source§impl<T: Clone> Clone for DelayBuffer<T>
impl<T: Clone> Clone for DelayBuffer<T>
Source§fn clone(&self) -> DelayBuffer<T>
fn clone(&self) -> DelayBuffer<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T> Freeze for DelayBuffer<T>
impl<T> RefUnwindSafe for DelayBuffer<T>where
T: RefUnwindSafe,
impl<T> Send for DelayBuffer<T>where
T: Send,
impl<T> Sync for DelayBuffer<T>where
T: Sync,
impl<T> Unpin for DelayBuffer<T>where
T: Unpin,
impl<T> UnsafeUnpin for DelayBuffer<T>
impl<T> UnwindSafe for DelayBuffer<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more