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>
impl<'a, Item, Si: Sink<Item> + Unpin + ?Sized> Permit<'a, Si, Item>
sourcepub fn feed(self, item: Item) -> Result<(), Si::Error>
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.
sourcepub fn send(self, item: Item) -> Result<Flush<'a, Si, Item>, Si::Error>
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:
- A synchronous part, which sends the item to the sink. This part is identical to
Self::feed
. - 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.