Queue

Struct Queue 

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

Queue that is limited in size and supports resizing.

This queue implementation has the following characteristics:

  • Resizable (deadqueue::resizable::Queue)
  • Based on deadqueue::unlimited::Queue
  • Has limited capacity with back pressure on push
  • Supports resizing
  • Enabled via the resizable 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 to the queue. If the queue is currently full return the object 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. Note: this can give an incorrect result if a simultaneous push/pop and resize ocurr while this function is executing. try_push() is the reccomended and safer mechanism in most circumstances. This method is provided as a convenience API.

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.

Source

pub async fn resize(&self, target_capacity: usize)

Resize queue. This increases or decreases the queue capacity accordingly.

Note: Increasing the capacity of a queue happens without blocking unless a resize operation is already in progress. Decreasing the capacity can block if there are futures waiting to push items to the queue.

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> FromIterator<T> for Queue<T>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more

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>
where T: Unpin,

§

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.