Struct PriorityQueue

Source
pub struct PriorityQueue<T> { /* private fields */ }
Expand description

An async-aware priority queue.

Implementations§

Source§

impl<T: Ord> PriorityQueue<T>

Source

pub fn new() -> Self

Source

pub fn push(&self, item: T)

Pushes an item into the queue. It will be removed in an order consistent with the ordering of itself relative to other items in the queue at the time of removal.

Source

pub fn try_pop(&self) -> Option<T>

Attempts to remove the item with the highest priority from the queue, returning None if there are no available items.

Source

pub fn pop(&self) -> PopFut<'_, T>

Removes the item with the highest priority from the queue, waiting for an item should there not be one immediately available.

Items are removed from the queue on a ‘first come, first served’ basis.

Source

pub fn incoming(&self) -> IncomingStream<'_, T>

Returns a stream of highest-priority items from this queue.

Items are removed from the queue on a ‘first come, first served’ basis.

Source

pub fn pending(&self) -> impl Iterator<Item = T> + '_

Returns an iterator of pending items from the queue (i.e: those that have already been inserted). Items will only be removed from the queue as the iterator is advanced.

Source

pub fn drain(&self) -> impl ExactSizeIterator<Item = T> + FusedIterator

Returns an iterator of items currently occupying the queue, immediately draining the queue.

Source

pub fn len(&self) -> usize

Return the number of items currently occupying the priority queue.

Because the queue is asynchronous, this information should be considered out of date immediately and, as such, should only be used for the purpose of logging, heuristics, etc.

Source

pub fn is_empty(&self) -> bool

Return true if the priority queue is currently empty.

Because the queue is asynchronous, this information should be considered out of date immediately and, as such, should only be used for the purpose of logging, heuristics, etc.

Trait Implementations§

Source§

impl<T: Ord> Default for PriorityQueue<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for PriorityQueue<T>

§

impl<T> RefUnwindSafe for PriorityQueue<T>

§

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

§

impl<T> Sync for PriorityQueue<T>
where T: Send,

§

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

§

impl<T> UnwindSafe for PriorityQueue<T>

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> 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, 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.