Queue

Struct Queue 

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

Queue that is limited in size and does not support resizing.

This queue implementation has the following characteristics:

  • Based on crossbeam_queue::ArrayQueue
  • Has limit capacity with back pressure on push
  • Does not support resizing
  • Enabled via the limited feature in your Cargo.toml

Implementations§

Source§

impl<T> Queue<T>

Source

pub fn new(max_size: usize) -> Self

Create new empty queue

Source

pub async fn pop(&self) -> T

Get an item from the queue. If the queue is currently empty this method blocks until an item is available.

Source

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

Try to get an item from the queue. If the queue is currently empty return None instead.

Source

pub async fn push(&self, item: T)

Push an item into the queue

Source

pub fn try_push(&self, item: T) -> Result<(), T>

Try to push an item into the queue. If the queue is full the item is returned as Err<T>.

Source

pub fn capacity(&self) -> usize

Get capacity of the queue (maximum number of items queue can store)

Source

pub fn len(&self) -> usize

Get current length of queue (number of items currently stored)

Source

pub fn is_empty(&self) -> bool

Returns true if the queue is empty.

Source

pub fn is_full(&self) -> bool

Returns true if the queue is full.

Source

pub fn available(&self) -> isize

The number of available items in the queue. If there are no items in the queue this number can become negative and stores the number of futures waiting for an item.

Source

pub async fn wait_full(&self)

Await until the queue is full.

Source

pub fn subscribe_full(&self) -> Receiver

Get a Receiver object that can repeatedly be awaited for queue-full notifications.

Source

pub async fn wait_empty(&self)

Await until the queue is empty.

Source

pub fn subscribe_empty(&self) -> Receiver

Get a Receiver object that can repeatedly be awaited for queue-empty notifications.

Trait Implementations§

Source§

impl<T> Debug for Queue<T>

Source§

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

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

impl<T, I> From<I> for Queue<T>
where I: IntoIterator<Item = T>, <I as IntoIterator>::IntoIter: ExactSizeIterator,

Source§

fn from(iter: I) -> Self

Create new queue from the given exact size iterator of objects.

Auto Trait Implementations§

§

impl<T> !Freeze for Queue<T>

§

impl<T> RefUnwindSafe for Queue<T>

§

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

§

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

§

impl<T> Unpin for Queue<T>

§

impl<T> UnwindSafe for Queue<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.