pub struct TimeQueue<T> { /* private fields */ }
Expand description
A time queue that delays yielding inserted elements until a fixed timeout has elapsed. Each inserted element is stored together with its expiration time (current Tokio Instant plus the constant timeout). Since the timeout is constant, the elements naturally expire in FIFO order, and both push and pop operations are O(1).
Implementations§
Source§impl<T> TimeQueue<T>
impl<T> TimeQueue<T>
Sourcepub fn with_capacity(timeout: Duration, capacity: usize) -> Self
pub fn with_capacity(timeout: Duration, capacity: usize) -> Self
Creates a new TimeQueue
with the given timeout and reserves capacity for the underlying queue.
Sourcepub fn push(&mut self, element: T)
pub fn push(&mut self, element: T)
Inserts an element into the queue. The element will be yielded after
timeout
has elapsed from the time of insertion.
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
Trait Implementations§
Source§impl<T> Stream for TimeQueue<T>
impl<T> Stream for TimeQueue<T>
impl<T> Unpin for TimeQueue<T>
Auto Trait Implementations§
impl<T> Freeze for TimeQueue<T>
impl<T> !RefUnwindSafe for TimeQueue<T>
impl<T> Send for TimeQueue<T>where
T: Send,
impl<T> Sync for TimeQueue<T>where
T: Sync,
impl<T> !UnwindSafe for TimeQueue<T>
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