Struct cancel_safe_futures::sink::Permit

source ·
pub struct Permit<'a, Si: ?Sized, Item> { /* private fields */ }
Expand description

A permit to send an item to a sink.

Permits are issued by the reserve and flush_reserve adapters, and indicate that Sink::poll_ready has completed and that the sink is now ready to accept an item.

Implementations§

source§

impl<'a, Item, Si: Sink<Item> + Unpin + ?Sized> Permit<'a, Si, Item>

source

pub fn feed(self, item: Item) -> Result<(), Si::Error>

Sends an item to the sink, akin to the SinkExt::feed adapter.

Unlike SinkExt::feed, Permit::feed is a synchronous method. This is because a Permit indicates that Sink::poll_ready has been called already, so the sink is immediately ready to accept an item.

source

pub fn send(self, item: Item) -> Result<Flush<'a, Si, Item>, Si::Error>

Sends an item to the sink and then flushes it, akin to the SinkExt::send adapter.

Unlike SinkExt::send, Permit::send has two parts:

  1. A synchronous part, which sends the item to the sink. This part is identical to Self::feed.
  2. An asynchronous part, which flushes the sink via the SinkExt::flush adapter.

This structure means that users get immediate feedback about, and can then await the resulting Flush future, or cancel it if necessary.

§Cancel safety

The returned Flush future is cancel-safe. If it is dropped, the sink will no longer be flushed. It is recommended that flush() be called explicitly, either by itself or via the flush_reserve adapter.

Trait Implementations§

source§

impl<'a, Si: Debug + ?Sized, Item: Debug> Debug for Permit<'a, Si, Item>

source§

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

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

impl<Si: Unpin + ?Sized, Item> Unpin for Permit<'_, Si, Item>

Auto Trait Implementations§

§

impl<'a, Si, Item> Freeze for Permit<'a, Si, Item>
where Si: ?Sized,

§

impl<'a, Si, Item> RefUnwindSafe for Permit<'a, Si, Item>
where Si: RefUnwindSafe + ?Sized,

§

impl<'a, Si, Item> Send for Permit<'a, Si, Item>
where Si: Send + ?Sized,

§

impl<'a, Si, Item> Sync for Permit<'a, Si, Item>
where Si: Sync + ?Sized,

§

impl<'a, Si, Item> !UnwindSafe for Permit<'a, Si, Item>

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.