Trait SinkExt
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: Self, f: F) -> With<Self, Item, U, Fut, F> where F: FnMut(U) -> Fut, Fut: Future<Output = Result<Item, E>>, E: From<<Self as >::Error>, Self: SizedComposes 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: Self, f: F) -> WithFlatMap<Self, Item, U, St, F> where F: FnMut(U) -> St, St: Stream<Item = Result<Item, <Self as >::Error>>, Self: SizedComposes 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: Self, f: F) -> SinkMapErr<Self, F> where F: FnOnce(<Self as >::Error) -> E, Self: SizedTransforms the error returned by the sink.
fn sink_err_into<E>(self: Self) -> SinkErrInto<Self, Item, E> where Self: Sized, <Self as >::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: Self, capacity: usize) -> Buffer<Self, Item> where Self: SizedAdds 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(self: &mut Self) -> Close<'_, Self, Item> where Self: UnpinClose the sink.
fn fanout<Si>(self: Self, other: Si) -> Fanout<Self, Si> where Self: Sized, Item: Clone, Si: Sink<Item, Error = <Self as >::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(self: &mut Self) -> Flush<'_, Self, Item> where Self: UnpinFlush 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(self: &mut Self, item: Item) -> Send<'_, Self, Item> where Self: UnpinA 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(self: &mut Self, item: Item) -> Feed<'_, Self, Item> where Self: UnpinA 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>(self: &'a mut Self, stream: &'a mut St) -> SendAll<'a, Self, St> where St: TryStream<Ok = Item, Error = <Self as >::Error> + Stream + Unpin + ?Sized, Self: UnpinA 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: Self) -> Either<Self, Si2> where Si2: Sink<Item, Error = <Self as >::Error>, Self: SizedWrap 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: Self) -> Either<Si1, Self> where Si1: Sink<Item, Error = <Self as >::Error>, Self: SizedWrap 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(self: &mut Self, cx: &mut Context<'_>) -> Poll<Result<(), <Self as >::Error>> where Self: UnpinA convenience method for calling
Sink::poll_readyonUnpinsink types.fn start_send_unpin(self: &mut Self, item: Item) -> Result<(), <Self as >::Error> where Self: UnpinA convenience method for calling
Sink::start_sendonUnpinsink types.fn poll_flush_unpin(self: &mut Self, cx: &mut Context<'_>) -> Poll<Result<(), <Self as >::Error>> where Self: UnpinA convenience method for calling
Sink::poll_flushonUnpinsink types.fn poll_close_unpin(self: &mut Self, cx: &mut Context<'_>) -> Poll<Result<(), <Self as >::Error>> where Self: UnpinA convenience method for calling
Sink::poll_closeonUnpinsink types.
Implementors
impl<T, Item> SinkExt for IntoStream<St>impl<T, Item> SinkExt for Then<St, Fut, F>impl<T, Item> SinkExt for TryFlatten<St>impl<T, Item> SinkExt for SplitSink<S, Item>impl<T, Item> SinkExt for TryFilterMap<St, Fut, F>impl<T, Item> SinkExt for Inspect<St, F>impl<T, Item> SinkExt for With<Si, Item, U, Fut, F>impl<T, Item> SinkExt for SinkMapErr<Si, F>impl<T, Item> SinkExt for Fanout<Si1, Si2>impl<T, Item> SinkExt for SinkErrInto<Si, Item, E>impl<T, Item> SinkExt for WithFlatMap<Si, Item, U, St, F>impl<T, Item> SinkExt for Unfold<T, F, R>impl<T, Item> SinkExt for Flatten<St>impl<T, Item> SinkExt for Either<A, B>impl<T, Item> SinkExt for BufferUnordered<St>impl<T, Item> SinkExt for MapErr<St, F>impl<T, Item> SinkExt for Enumerate<St>impl<T, Item> SinkExt for FlattenStream<F>impl<T, Item> SinkExt for TryTakeWhile<St, Fut, F>impl<T, Item> SinkExt for TryChunks<St>impl<T, Item> SinkExt for FlattenSink<Fut, Si>impl<T, Item> SinkExt for FlatMapUnordered<St, U, F>impl<T, Item> SinkExt for Filter<St, Fut, F>impl<T, Item> SinkExt for Peekable<St>impl<T, Item> SinkExt for TakeWhile<St, Fut, F>impl<T, Item> SinkExt for ErrInto<St, E>impl<T, Item> SinkExt for TakeUntil<St, Fut>impl<T, Item> SinkExt for TrySkipWhile<St, Fut, F>impl<T, Item> SinkExt for FlatMap<St, U, F>impl<T, Item> SinkExt for TryFilter<St, Fut, F>impl<T, Item> SinkExt for IntoSink<W, Item>impl<T, Item> SinkExt for Scan<St, S, Fut, F>impl<T, Item> SinkExt for Fuse<St>impl<T, Item> SinkExt for ReadyChunks<St>impl<T, Item> SinkExt for TryFlattenStream<Fut>impl<T, Item> SinkExt for InspectErr<St, F>impl<T, Item> SinkExt for OrElse<St, Fut, F>impl<T, Item> SinkExt for Take<St>impl<T, Item> SinkExt for SkipWhile<St, Fut, F>impl<T, Item> SinkExt for AndThen<St, Fut, F>impl<T, Item> SinkExt for TryBuffered<St>impl<T, Item> SinkExt for Buffer<Si, Item>impl<T, Item> SinkExt for Drain<T>impl<T, Item> SinkExt for Timpl<T, Item> SinkExt for Buffered<St>impl<T, Item> SinkExt for Chunks<St>impl<T, Item> SinkExt for InspectOk<St, F>impl<T, Item> SinkExt for Skip<St>impl<T, Item> SinkExt for TryFlattenUnordered<St>impl<T, Item> SinkExt for TryReadyChunks<St>impl<T, Item> SinkExt for TryBufferUnordered<St>impl<T, Item> SinkExt for Map<St, F>impl<T, Item> SinkExt for FilterMap<St, Fut, F>impl<T, Item> SinkExt for MapOk<St, F>