pub struct Inbox<T> { /* private fields */ }Expand description
A bounded FIFO receive queue with a default message TTL.
Items pushed without an explicit TTL use the default. Pass default_ttl_secs = 0
for items that never expire.
§Examples
use ma_core::Inbox;
let mut inbox: Inbox<&str> = Inbox::new(64, 300);
let now = 1_000_000;
inbox.push(now, "hello");
assert_eq!(inbox.pop(now), Some("hello"));
// After the TTL expires, the message is gone:
inbox.push(now, "ephemeral");
assert_eq!(inbox.pop(now + 301), None);Implementations§
Source§impl<T> Inbox<T>
impl<T> Inbox<T>
Sourcepub fn new(capacity: usize, default_ttl_secs: u64) -> Self
pub fn new(capacity: usize, default_ttl_secs: u64) -> Self
Create an inbox with the given capacity and default TTL (seconds).
default_ttl_secs = 0 means items never expire by default.
Sourcepub fn push_with_ttl(&mut self, now: u64, ttl_secs: u64, item: T)
pub fn push_with_ttl(&mut self, now: u64, ttl_secs: u64, item: T)
Push an item with a custom TTL (seconds). ttl_secs = 0 means no expiry.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Inbox<T>
impl<T> RefUnwindSafe for Inbox<T>where
T: RefUnwindSafe,
impl<T> Send for Inbox<T>where
T: Send,
impl<T> Sync for Inbox<T>where
T: Sync,
impl<T> Unpin for Inbox<T>where
T: Unpin,
impl<T> UnsafeUnpin for Inbox<T>
impl<T> UnwindSafe for Inbox<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