Struct lilos::spsc::Pusher

source ·
pub struct Pusher<'a, T> { /* private fields */ }
Expand description

Queue endpoint for pushing data. Access to a Pusher only gives you the right to push data and enquire about push-related properties.

See the module docs for more details.

Implementations§

source§

impl<'q, T> Pusher<'q, T>

source

pub fn can_push(&self) -> bool

Checks if there is room to push at least one item. Because the Pusher endpoint has exclusive control over data movement into the queue, if this returns true, the condition will remain true until a push or try_push happens through self, or self is dropped.

If this returns false, of course, room may appear at any time if the other end of the queue is popped.

source

pub fn try_reserve(&mut self) -> Option<Entry<'q, T>>

Checks if there is room to push at least one item, and if so, returns an Entry that entitles its holder to that queue slot.

If the queue is full, returns None.

source

pub async fn reserve<'s>(&'s mut self) -> Entry<'s, T>

Produces a future that resolves when there is enough space in the queue to push one element. It resolves into an Entry, which entitles the holder to pushing an element without needing to check or await. This is a deliberate design choice – it means you can cancel the future without losing the element you were trying to push.

The returned Entry borrows self exclusively. This means you must use the Entry, or drop it, before you can request another. This prevents a deadlock, where you wait for a second permit that will never emerge.

The future produced by reserve also borrows self exclusively. This means you can’t simultaneously have two futures waiting for permits from the same Pusher. This wouldn’t necessarily be a bad thing, but we need to maintain the exclusive borrow in order to pass it through to the Entry.

§Cancellation

Cancel Safety: Strict.

This does basically nothing if cancelled (it is intrinsically cancel-safe).

source

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

Attempts to stuff value into the queue.

If there is space, ownership of value moves into the queue and this returns Ok(()).

If there is not space, this returns Err(value) – that is, ownership of value is handed back to you.

Trait Implementations§

source§

impl<'a, T: Debug> Debug for Pusher<'a, T>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for Pusher<'a, T>

§

impl<'a, T> !RefUnwindSafe for Pusher<'a, T>

§

impl<'a, T> Send for Pusher<'a, T>
where T: Send,

§

impl<'a, T> !Sync for Pusher<'a, T>

§

impl<'a, T> Unpin for Pusher<'a, T>

§

impl<'a, T> !UnwindSafe for Pusher<'a, 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>,

§

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>,

§

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.
source§

impl<U, T> Captures<T> for U
where U: ?Sized,

source§

impl<U, T> Captures<T> for U
where U: ?Sized,