Struct Faucet

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

A back-pressured queue limited in size that can be drained after signaling completion.

This queue implementation has the following characteristics:

  • Based on deadqueue::limited::Queue
  • Has limited capacity with back-pressure on push
  • Can signal completion by calling end() or by providing a cancellation token and calling cancel() on it
  • Once completion is signaled, no additional values can be pushed while any values remaining in the queue can be drained

Implementations§

Source§

impl<T> Faucet<T>

Source

pub fn new(max_len: usize) -> Self

Creates a new faucet with a maximum queue length.

Source

pub fn new_with_cancellation( max_len: usize, cancellation: CancellationToken, ) -> Self

Creates a new faucet with a maximum queue length and a cancellation source.

Providing an existing cancellation token is useful when you have a “parent” cancellation token.

Cancelling the token will prevent any additional values from being pushed onto the queue, and will drain any values already in the queue.

Source

pub fn end(&self)

Cancels the faucet, preventing any additional values from being pushed onto the queue. Any values already in the queue will be drained.

Source

pub fn is_finished(&self) -> bool

Returns true if the faucet has been cancelled and has no more values remaining in the queue to be drained.

Source

pub fn is_pending(&self) -> bool

Returns true if the faucet is either: (a) accepting values, or (b) is cancelled but has not been fully drained.

Source

pub fn is_cancelled(&self) -> bool

Returns true if the faucet has been cancelled and will not accept any additional values pushed onto the queue.

Source

pub async fn push(&self, value: T) -> ControlFlow<(), ()>

Pushes a value onto the queue or waits until space is available.

Source

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

Attempts to push a value onto the queue, returning Err(value) if the queue is full or has been cancelled.

Source

pub async fn next(&self) -> Option<T>

Attempts to pop a value from the queue, returning None if the queue is has been cancelled and finished draining.

Source

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

Attempts to pop a value from the queue, returning None if the queue is currently empty.

Source

pub fn len(&self) -> usize

The number of items currently stored in the queue.

Source

pub fn capacity(&self) -> usize

The maximum number of items that can be stored in the queue.

Trait Implementations§

Source§

impl<T> Clone for Faucet<T>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Faucet<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Faucet<T>

§

impl<T> !RefUnwindSafe for Faucet<T>

§

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

§

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

§

impl<T> Unpin for Faucet<T>

§

impl<T> !UnwindSafe for Faucet<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.