Struct WakerQueue

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

A ConcurrentQueue with a Waker attached. Allows rapid implementation of fast channels where at least one side may not be cloned. Caution: Last Write wins and you are asking for trouble if there are races registering Wakers. See atomic_waker for details.

Implementations§

Source§

impl<T: 'static + Send> WakerQueue<T>

Source

pub fn bounded(size: usize) -> WakerQueue<T>

Create a WakerQueue with the given capacity.

Source

pub fn unbounded() -> WakerQueue<T>

Create a WakerQueue which will dynamically resize as required.

Source

pub fn is_empty(&self) -> bool

true if the WakerQueue has no items.

Source

pub fn is_full(&self) -> bool

true if the WakerQueue has no spare capacity.

Source

pub fn len(&self) -> usize

Count of items in the WakerQueue

Source

pub fn capacity(&self) -> Option<usize>

Returns the maximum capacity of the queue. None for unbounded queues.

Source

pub fn close(&self)

Closes the queue so that no more items can be pushed. Pops are allowed.

Source

pub fn is_closed(&self) -> bool

true if the queue is closed

Source

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

Attempt to push an item into the queue. Will fail if the queue is full or closed.

Source

pub fn try_push_wake(&self, value: T, wake: bool) -> Result<(), PushError<T>>

Attempts a push. If successful and wake is true, wakes the last registered Waker.

Source

pub fn try_push_wake_empty(&self, value: T) -> Result<(), PushError<T>>

Attempts a push. If successful and the queue was previously empty, wakes the last registered Waker.

Source

pub fn try_push_wake_full(&self, value: T) -> Result<(), PushError<T>>

Attempts a push. If successful and wake is true, wakes the last registered Waker.

Source

pub fn try_pop(&self) -> Result<T, PopError>

Attempts to pop an item from the queue. Will fail if the queue is empty.

Source

pub fn try_pop_wake(&self, wake: bool) -> Result<T, PopError>

Attempts a pop. If successful and wake is true, wakes the last registered Waker.

Source

pub fn try_pop_wake_empty(&self) -> Result<T, PopError>

Attempts a pop. If successful and the queue was previously empty, wakes the last registered Waker.

Source

pub fn try_pop_wake_full(&self) -> Result<T, PopError>

Attempts a pop. If successful and the queue was previously full, wakes the last registered Waker.

Source

pub fn push<'a, F>(&'a self, value: T, wake_if: F) -> Push<'a, T, F>
where F: Fn(&'a WakerQueue<T>) -> bool,

Returns a future which pushes into a WakerQueue

Source

pub fn pop<'a, F>(&'a self, wake_if: F) -> Pop<'a, T, F>
where F: Fn(&'a WakerQueue<T>) -> bool,

Returns a future which pops from a WakerQueue

Source

pub fn register(&self, waker: &Waker)

Registers a waker with the WakerQueue.

Source

pub fn wake(&self)

Wakes the last registered Waker, if any.

Source

pub fn wake_if(&self, wake: bool)

Wakes the last registered Waker, if any, if wake is true.

Source

pub fn poll_pop(&self, ctx: &Context<'_>) -> Result<T, PopError>

Attempts to pop. If it fails because the queue is empty, it registers the Waker from the provided context.

Source

pub fn poll_push(&self, value: T, ctx: &Context<'_>) -> Result<(), PushError<T>>

Attempts to push. If it fails because the queue is full, it registers the Waker from the provided context.

Trait Implementations§

Source§

impl<T: Debug> Debug for WakerQueue<T>

Source§

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

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

impl<T: 'static + Send> Send for WakerQueue<T>

Source§

impl<T: 'static + Send> Sync for WakerQueue<T>

Auto Trait Implementations§

§

impl<T> !Freeze for WakerQueue<T>

§

impl<T> !RefUnwindSafe for WakerQueue<T>

§

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

§

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