Skip to main content

Item

Struct Item 

Source
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>

Source

pub fn new(data: T) -> Self

Creates a queue item.

§Examples
use zrx_store::queue::Item;

// Create queue item
let item = Item::new(42);
Source

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());
Source§

impl<T> Item<T>

Source

pub fn deadline(&self) -> Instant

Returns the deadline.

Source

pub fn data(&self) -> &T

Returns a reference to the associated data.

Trait Implementations§

Source§

impl<T: Clone> Clone for Item<T>

Source§

fn clone(&self) -> Item<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Item<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Ord for Item<T>
where T: Eq,

Source§

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) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T> PartialEq for Item<T>
where T: PartialEq,

Source§

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);
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialOrd for Item<T>
where T: Eq,

Source§

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);
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> Eq for Item<T>
where T: Eq,

Auto Trait Implementations§

§

impl<T> Freeze for Item<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Item<T>
where T: RefUnwindSafe,

§

impl<T> Send for Item<T>
where T: Send,

§

impl<T> Sync for Item<T>
where T: Sync,

§

impl<T> Unpin for Item<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Item<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Item<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Value for T
where T: Debug + Eq + 'static,