pub struct TtlQueue<T> { /* private fields */ }Expand description
A bounded FIFO queue where each item carries an expiry timestamp.
Expired items are evicted lazily on push, pop, and drain.
When the queue is at capacity, the oldest item is dropped on push.
§Examples
use ma_core::TtlQueue;
let mut q = TtlQueue::new(8);
let now = 100;
q.push(now, now + 60, "expires in 60s");
q.push(now, 0, "never expires");
// Both present at t=100
assert_eq!(q.drain(now).len(), 2);Implementations§
Source§impl<T> TtlQueue<T>
impl<T> TtlQueue<T>
Sourcepub fn push(&mut self, now: u64, expires_at: u64, item: T)
pub fn push(&mut self, now: u64, expires_at: u64, item: T)
Push an item with an absolute expiry timestamp (Unix epoch seconds).
Pass expires_at = 0 for items that never expire.
If the queue is full after eviction, the oldest item is silently dropped.
Sourcepub fn pop(&mut self, now: u64) -> Option<T>
pub fn pop(&mut self, now: u64) -> Option<T>
Pop the oldest non-expired item, evicting any expired head entries first.
Sourcepub fn peek(&mut self, now: u64) -> Option<&T>
pub fn peek(&mut self, now: u64) -> Option<&T>
Peek at the oldest non-expired item without removing it.
Sourcepub fn drain(&mut self, now: u64) -> Vec<T>
pub fn drain(&mut self, now: u64) -> Vec<T>
Drain all non-expired items, returning them in FIFO order.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for TtlQueue<T>
impl<T> RefUnwindSafe for TtlQueue<T>where
T: RefUnwindSafe,
impl<T> Send for TtlQueue<T>where
T: Send,
impl<T> Sync for TtlQueue<T>where
T: Sync,
impl<T> Unpin for TtlQueue<T>where
T: Unpin,
impl<T> UnsafeUnpin for TtlQueue<T>
impl<T> UnwindSafe for TtlQueue<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