Struct js_utils::queue::Queue

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

FIFO queue with async pop.

Implementations§

source§

impl<T> Queue<T>

source

pub fn new() -> Self

Creates new queue with unbounded capacity.

source

pub fn with_capacity(capacity: usize) -> Self

Creates new queue with given capacity.

capacity must be greater than 0 - it’ll panic otherwise.

source

pub fn push(&self, element: T)

Pushes element into the queue.

If queue is full it will push out the last (oldest) element out of the queue.

source

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

Pops (asynchronously) element off the queue.

It means that if queue is currently empty await will wait till element is pushed into the queue.

source

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

Pops element off the queue.

Returns None if queue is currently empty.

source

pub fn len(&self) -> usize

Returns count of elements currently in the queue.

source

pub fn is_empty(&self) -> bool

Returns true if queue is currently empty.

source

pub fn is_full(&self) -> bool

Returns true if queue is currently full.

Trait Implementations§

source§

impl<T> Default for Queue<T>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Queue<T>

§

impl<T> !Send for Queue<T>

§

impl<T> !Sync for Queue<T>

§

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

§

impl<T> !UnwindSafe for Queue<T>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.