pub struct Item<T = usize> { /* private fields */ }Expand description
Queue item.
Items are stored in queues, and can have arbitrary associated data. An item has a specific deadline, which is the ordering property of the queue.
Items must only be considered for processing when their deadline has passed,
which is exactly what Queue::take ensures. This allows to implement
timers and intervals in an efficient manner. In case two items have the
same deadline, order is undefined, but this doesn’t matter for us.
Note that mutable data needs to be stored outside of the queue, as items are
immutable. The built-in Queue uses a Slab for this matter.
Implementations§
Source§impl<T> Item<T>
impl<T> Item<T>
Sourcepub fn new(data: T) -> Self
pub fn new(data: T) -> Self
Creates a queue item.
§Examples
use zrx_store::queue::Item;
// Create queue item
let item = Item::new(42);Sourcepub fn set_deadline(&mut self, deadline: Instant)
pub fn set_deadline(&mut self, deadline: Instant)
Updates the deadline of the queue item.
§Examples
use std::time::Instant;
use zrx_store::queue::Item;
// Create queue item and set deadline
let mut item = Item::new(42);
item.set_deadline(Instant::now());Trait Implementations§
Source§impl<T> Ord for Item<T>where
T: Eq,
impl<T> Ord for Item<T>where
T: Eq,
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
Orders two queue items.
§Examples
use zrx_store::queue::Item;
// Create and compare queue items
let a = Item::new(42);
let b = Item::new(84);
assert!(a <= b);1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T> PartialEq for Item<T>where
T: PartialEq,
impl<T> PartialEq for Item<T>where
T: PartialEq,
Source§fn eq(&self, other: &Self) -> bool
fn eq(&self, other: &Self) -> bool
Compares two queue items for equality.
Note that two queue items are considered being equal if their associated data is equal. Deadlines are solely relevant for ordering.
§Examples
use zrx_store::queue::Item;
// Create and compare queue items
let a = Item::new(42);
let b = Item::new(42);
assert_eq!(a, b);Source§impl<T> PartialOrd for Item<T>where
T: Eq,
impl<T> PartialOrd for Item<T>where
T: Eq,
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Orders two queue items.
§Examples
use zrx_store::queue::Item;
// Create and compare queue items
let a = Item::new(42);
let b = Item::new(84);
assert!(a <= b);