Trait SinkExt
pub trait SinkExt<Item>: Sink<Item>
An extension trait for Sinks that provides a variety of convenient
combinator functions.
Provided Methods
fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F> where F: FnMut(U) -> Fut, Fut: Future<Output = Result<Item, E>>, E: From<Self::Error>, Self: Sized,Composes a function in front of the sink.
This adapter produces a new sink that passes each value through the given function
fbefore sending it toself.To process each value,
fproduces a future, which is then polled to completion before passing its result down to the underlying sink. If the future produces an error, that error is returned by the new sink.Note that this function consumes the given sink, returning a wrapped version, much like
Iterator::map.fn with_flat_map<U, St, F>(self, f: F) -> WithFlatMap<Self, Item, U, St, F> where F: FnMut(U) -> St, St: Stream<Item = Result<Item, Self::Error>>, Self: Sized,Composes a function in front of the sink.
This adapter produces a new sink that passes each value through the given function
fbefore sending it toself.To process each value,
fproduces a stream, of which each value is passed to the underlying sink. A new value will not be accepted until the stream has been drainedNote that this function consumes the given sink, returning a wrapped version, much like
Iterator::flat_map.Examples
# block_on;fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F> where F: FnOnce(Self::Error) -> E, Self: Sized,Transforms the error returned by the sink.
fn sink_err_into<E>(self) -> SinkErrInto<Self, Item, E> where Self: Sized, Self::Error: Into<E>,Map this sink's error to a different error type using the
Intotrait.If wanting to map errors of a
Sink + Stream, use.sink_err_into().err_into().fn buffer(self, capacity: usize) -> Buffer<Self, Item> where Self: Sized,Adds a fixed-size buffer to the current sink.
The resulting sink will buffer up to
capacityitems when the underlying sink is unwilling to accept additional items. Callingflushon the buffered sink will attempt to both empty the buffer and complete processing on the underlying sink.Note that this function consumes the given sink, returning a wrapped version, much like
Iterator::map.This method is only available when the
stdorallocfeature of this library is activated, and it is activated by default.fn close(&mut self) -> Close<'_, Self, Item> where Self: Unpin,Close the sink.
fn fanout<Si>(self, other: Si) -> Fanout<Self, Si> where Self: Sized, Item: Clone, Si: Sink<Item, Error = Self::Error>,Fanout items to multiple sinks.
This adapter clones each incoming item and forwards it to both this as well as the other sink at the same time.
fn flush(&mut self) -> Flush<'_, Self, Item> where Self: Unpin,Flush the sink, processing all pending items.
This adapter is intended to be used when you want to stop sending to the sink until all current requests are processed.
fn send(&mut self, item: Item) -> Send<'_, Self, Item> where Self: Unpin,A future that completes after the given item has been fully processed into the sink, including flushing.
Note that, because of the flushing requirement, it is usually better to batch together items to send via
feedorsend_all, rather than flushing between each item.fn feed(&mut self, item: Item) -> Feed<'_, Self, Item> where Self: Unpin,A future that completes after the given item has been received by the sink.
Unlike
send, the returned future does not flush the sink. It is the caller's responsibility to ensure all pending items are processed, which can be done viaflushorclose.fn send_all<'a, St>(&'a mut self, stream: &'a mut St) -> SendAll<'a, Self, St> where St: TryStream<Ok = Item, Error = Self::Error> + Stream + Unpin + ?Sized, Self: Unpin,A future that completes after the given stream has been fully processed into the sink, including flushing.
This future will drive the stream to keep producing items until it is exhausted, sending each item to the sink. It will complete once both the stream is exhausted, the sink has received all items, and the sink has been flushed. Note that the sink is not closed. If the stream produces an error, that error will be returned by this future without flushing the sink.
Doing
sink.send_all(stream)is roughly equivalent tostream.forward(sink). The returned future will exhaust all items fromstreamand send them toself.fn left_sink<Si2>(self) -> Either<Self, Si2> where Si2: Sink<Item, Error = Self::Error>, Self: Sized,Wrap this sink in an
Eithersink, making it the left-hand variant of thatEither.This can be used in combination with the
right_sinkmethod to writeifstatements that evaluate to different streams in different branches.fn right_sink<Si1>(self) -> Either<Si1, Self> where Si1: Sink<Item, Error = Self::Error>, Self: Sized,Wrap this stream in an
Eitherstream, making it the right-hand variant of thatEither.This can be used in combination with the
left_sinkmethod to writeifstatements that evaluate to different streams in different branches.fn poll_ready_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> where Self: Unpin,A convenience method for calling
Sink::poll_readyonUnpinsink types.fn start_send_unpin(&mut self, item: Item) -> Result<(), Self::Error> where Self: Unpin,A convenience method for calling
Sink::start_sendonUnpinsink types.fn poll_flush_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> where Self: Unpin,A convenience method for calling
Sink::poll_flushonUnpinsink types.fn poll_close_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> where Self: Unpin,A convenience method for calling
Sink::poll_closeonUnpinsink types.
Implementors
impl<T, Item> SinkExt<Item> for AndThen<St, Fut, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Buffer<Si, Item> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for BufferUnordered<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Buffered<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Chunks<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Drain<T> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Either<A, B> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Enumerate<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for ErrInto<St, E> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Fanout<Si1, Si2> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Filter<St, Fut, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for FilterMap<St, Fut, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for FlatMap<St, U, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for FlatMapUnordered<St, U, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Flatten<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for FlattenSink<Fut, Si> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for FlattenStream<F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Fuse<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Inspect<St, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for InspectErr<St, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for InspectOk<St, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for IntoSink<W, Item> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for IntoStream<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Map<St, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for MapErr<St, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for MapOk<St, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for OrElse<St, Fut, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Peekable<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for ReadyChunks<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Scan<St, S, Fut, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for SinkErrInto<Si, Item, E> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for SinkMapErr<Si, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Skip<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for SkipWhile<St, Fut, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for SplitSink<S, Item> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for T where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Take<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for TakeUntil<St, Fut> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for TakeWhile<St, Fut, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Then<St, Fut, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for TryBufferUnordered<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for TryBuffered<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for TryChunks<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for TryFilter<St, Fut, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for TryFilterMap<St, Fut, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for TryFlatten<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for TryFlattenStream<Fut> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for TryFlattenUnordered<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for TryReadyChunks<St> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for TrySkipWhile<St, Fut, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for TryTakeWhile<St, Fut, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for Unfold<T, F, R> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for With<Si, Item, U, Fut, F> where T: Sink<Item> + ?Sized,impl<T, Item> SinkExt<Item> for WithFlatMap<Si, Item, U, St, F> where T: Sink<Item> + ?Sized,