Trait futures::sink::SinkExt[][src]

pub trait SinkExt<Item>: Sink<Item> {
    pub fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F>
    where
        E: From<Self::Error>,
        F: FnMut(U) -> Fut,
        Fut: Future<Output = Result<Item, E>>
, { ... }
pub 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>>
, { ... }
pub fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F>
    where
        F: FnOnce(Self::Error) -> E
, { ... }
pub fn sink_err_into<E>(self) -> SinkErrInto<Self, Item, E>
    where
        Self::Error: Into<E>
, { ... }
pub fn buffer(self, capacity: usize) -> Buffer<Self, Item> { ... }
pub fn close(&mut self) -> Close<'_, Self, Item>

Notable traits for Close<'_, Si, Item>

impl<'_, Si, Item> Future for Close<'_, Si, Item> where
    Si: Sink<Item> + Unpin + ?Sized
type Output = Result<(), <Si as Sink<Item>>::Error>;

    where
        Self: Unpin
, { ... }
pub fn fanout<Si>(self, other: Si) -> Fanout<Self, Si>
    where
        Item: Clone,
        Si: Sink<Item, Error = Self::Error>
, { ... }
pub fn flush(&mut self) -> Flush<'_, Self, Item>

Notable traits for Flush<'_, Si, Item>

impl<'_, Si, Item> Future for Flush<'_, Si, Item> where
    Si: Sink<Item> + Unpin + ?Sized
type Output = Result<(), <Si as Sink<Item>>::Error>;

    where
        Self: Unpin
, { ... }
pub fn send(&mut self, item: Item) -> Send<'_, Self, Item>

Notable traits for Send<'_, Si, Item>

impl<'_, Si, Item> Future for Send<'_, Si, Item> where
    Si: Sink<Item> + Unpin + ?Sized
type Output = Result<(), <Si as Sink<Item>>::Error>;

    where
        Self: Unpin
, { ... }
pub fn feed(&mut self, item: Item) -> Feed<'_, Self, Item>

Notable traits for Feed<'_, Si, Item>

impl<'_, Si, Item> Future for Feed<'_, Si, Item> where
    Si: Sink<Item> + Unpin + ?Sized
type Output = Result<(), <Si as Sink<Item>>::Error>;

    where
        Self: Unpin
, { ... }
pub fn send_all<St>(
        &'a mut self,
        stream: &'a mut St
    ) -> SendAll<'a, Self, St>

Notable traits for SendAll<'_, Si, St>

impl<'_, Si, St, Ok, Error> Future for SendAll<'_, Si, St> where
    Si: Sink<Ok, Error = Error> + Unpin + ?Sized,
    St: Stream<Item = Result<Ok, Error>> + Unpin + ?Sized
type Output = Result<(), Error>;

    where
        Self: Unpin,
        St: TryStream<Ok = Item, Error = Self::Error> + Stream + Unpin + ?Sized
, { ... }
pub fn left_sink<Si2>(self) -> Either<Self, Si2>

Notable traits for Either<A, B>

impl<A, B> Future for Either<A, B> where
    B: Future<Output = <A as Future>::Output>,
    A: Future
type Output = <A as Future>::Output;

    where
        Si2: Sink<Item, Error = Self::Error>
, { ... }
pub fn right_sink<Si1>(self) -> Either<Si1, Self>

Notable traits for Either<A, B>

impl<A, B> Future for Either<A, B> where
    B: Future<Output = <A as Future>::Output>,
    A: Future
type Output = <A as Future>::Output;

    where
        Si1: Sink<Item, Error = Self::Error>
, { ... }
pub fn poll_ready_unpin(
        &mut self,
        cx: &mut Context<'_>
    ) -> Poll<Result<(), Self::Error>>
    where
        Self: Unpin
, { ... }
pub fn start_send_unpin(&mut self, item: Item) -> Result<(), Self::Error>
    where
        Self: Unpin
, { ... }
pub fn poll_flush_unpin(
        &mut self,
        cx: &mut Context<'_>
    ) -> Poll<Result<(), Self::Error>>
    where
        Self: Unpin
, { ... }
pub fn poll_close_unpin(
        &mut self,
        cx: &mut Context<'_>
    ) -> Poll<Result<(), Self::Error>>
    where
        Self: Unpin
, { ... } }

An extension trait for Sinks that provides a variety of convenient combinator functions.

Provided methods

pub fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F> where
    E: From<Self::Error>,
    F: FnMut(U) -> Fut,
    Fut: Future<Output = Result<Item, E>>, 
[src]

Composes a function in front of the sink.

This adapter produces a new sink that passes each value through the given function f before sending it to self.

To process each value, f produces 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.

pub 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>>, 
[src]

Composes a function in front of the sink.

This adapter produces a new sink that passes each value through the given function f before sending it to self.

To process each value, f produces a stream, of which each value is passed to the underlying sink. A new value will not be accepted until the stream has been drained

Note that this function consumes the given sink, returning a wrapped version, much like Iterator::flat_map.

Examples

use futures::channel::mpsc;
use futures::sink::SinkExt;
use futures::stream::{self, StreamExt};

let (tx, rx) = mpsc::channel(5);

let mut tx = tx.with_flat_map(|x| {
    stream::iter(vec![Ok(42); x])
});

tx.send(5).await.unwrap();
drop(tx);
let received: Vec<i32> = rx.collect().await;
assert_eq!(received, vec![42, 42, 42, 42, 42]);

pub fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F> where
    F: FnOnce(Self::Error) -> E, 
[src]

Transforms the error returned by the sink.

pub fn sink_err_into<E>(self) -> SinkErrInto<Self, Item, E> where
    Self::Error: Into<E>, 
[src]

Map this sink’s error to a different error type using the Into trait.

If wanting to map errors of a Sink + Stream, use .sink_err_into().err_into().

pub fn buffer(self, capacity: usize) -> Buffer<Self, Item>[src]

Adds a fixed-size buffer to the current sink.

The resulting sink will buffer up to capacity items when the underlying sink is unwilling to accept additional items. Calling flush on 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 std or alloc feature of this library is activated, and it is activated by default.

pub fn close(&mut self) -> Close<'_, Self, Item>

Notable traits for Close<'_, Si, Item>

impl<'_, Si, Item> Future for Close<'_, Si, Item> where
    Si: Sink<Item> + Unpin + ?Sized
type Output = Result<(), <Si as Sink<Item>>::Error>;
where
    Self: Unpin
[src]

Close the sink.

pub fn fanout<Si>(self, other: Si) -> Fanout<Self, Si> where
    Item: Clone,
    Si: Sink<Item, Error = Self::Error>, 
[src]

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.

pub fn flush(&mut self) -> Flush<'_, Self, Item>

Notable traits for Flush<'_, Si, Item>

impl<'_, Si, Item> Future for Flush<'_, Si, Item> where
    Si: Sink<Item> + Unpin + ?Sized
type Output = Result<(), <Si as Sink<Item>>::Error>;
where
    Self: Unpin
[src]

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.

pub fn send(&mut self, item: Item) -> Send<'_, Self, Item>

Notable traits for Send<'_, Si, Item>

impl<'_, Si, Item> Future for Send<'_, Si, Item> where
    Si: Sink<Item> + Unpin + ?Sized
type Output = Result<(), <Si as Sink<Item>>::Error>;
where
    Self: Unpin
[src]

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 feed or send_all, rather than flushing between each item.

pub fn feed(&mut self, item: Item) -> Feed<'_, Self, Item>

Notable traits for Feed<'_, Si, Item>

impl<'_, Si, Item> Future for Feed<'_, Si, Item> where
    Si: Sink<Item> + Unpin + ?Sized
type Output = Result<(), <Si as Sink<Item>>::Error>;
where
    Self: Unpin
[src]

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 via flush or close.

pub fn send_all<St>(&'a mut self, stream: &'a mut St) -> SendAll<'a, Self, St>

Notable traits for SendAll<'_, Si, St>

impl<'_, Si, St, Ok, Error> Future for SendAll<'_, Si, St> where
    Si: Sink<Ok, Error = Error> + Unpin + ?Sized,
    St: Stream<Item = Result<Ok, Error>> + Unpin + ?Sized
type Output = Result<(), Error>;
where
    Self: Unpin,
    St: TryStream<Ok = Item, Error = Self::Error> + Stream + Unpin + ?Sized
[src]

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.

Doing sink.send_all(stream) is roughly equivalent to stream.forward(sink). The returned future will exhaust all items from stream and send them to self.

pub fn left_sink<Si2>(self) -> Either<Self, Si2>

Notable traits for Either<A, B>

impl<A, B> Future for Either<A, B> where
    B: Future<Output = <A as Future>::Output>,
    A: Future
type Output = <A as Future>::Output;
where
    Si2: Sink<Item, Error = Self::Error>, 
[src]

Wrap this sink in an Either sink, making it the left-hand variant of that Either.

This can be used in combination with the right_sink method to write if statements that evaluate to different streams in different branches.

pub fn right_sink<Si1>(self) -> Either<Si1, Self>

Notable traits for Either<A, B>

impl<A, B> Future for Either<A, B> where
    B: Future<Output = <A as Future>::Output>,
    A: Future
type Output = <A as Future>::Output;
where
    Si1: Sink<Item, Error = Self::Error>, 
[src]

Wrap this stream in an Either stream, making it the right-hand variant of that Either.

This can be used in combination with the left_sink method to write if statements that evaluate to different streams in different branches.

pub fn poll_ready_unpin(
    &mut self,
    cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>> where
    Self: Unpin
[src]

A convenience method for calling Sink::poll_ready on Unpin sink types.

pub fn start_send_unpin(&mut self, item: Item) -> Result<(), Self::Error> where
    Self: Unpin
[src]

A convenience method for calling Sink::start_send on Unpin sink types.

pub fn poll_flush_unpin(
    &mut self,
    cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>> where
    Self: Unpin
[src]

A convenience method for calling Sink::poll_flush on Unpin sink types.

pub fn poll_close_unpin(
    &mut self,
    cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>> where
    Self: Unpin
[src]

A convenience method for calling Sink::poll_close on Unpin sink types.

Loading content...

Implementors

impl<T, Item> SinkExt<Item> for T where
    T: Sink<Item> + ?Sized
[src]

Loading content...