pub trait StreamSink<SendItem, RecvItem = SendItem> {
    type Error;

    // Required methods
    fn poll_stream_sink(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>
    ) -> State<SendItem, Self::Error>;
    fn start_send(
        self: Pin<&mut Self>,
        item: RecvItem
    ) -> Result<(), Self::Error>;
    fn poll_close(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>
    ) -> Poll<Result<Option<SendItem>, Self::Error>>;
}
Expand description

Combines Stream and Sink into one trait.

Unlike each of it’s part, StreamSink is capable of simultaneously poll for sending and receiving. This allows for workflow such as packet processor to be done without making separate pipe for sending and receiving.

Required Associated Types§

source

type Error

The error type that it may return.

Required Methods§

source

fn poll_stream_sink( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> State<SendItem, Self::Error>

Poll the StreamSink.

Due to complexity of it’s state, it does not return the usual Poll enum like other poll-like methods. See State for more info.

source

fn start_send(self: Pin<&mut Self>, item: RecvItem) -> Result<(), Self::Error>

Starts sending item into StreamSink.

WARNING: May panics if StreamSink is not ready to receive.

source

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<Option<SendItem>, Self::Error>>

Close the StreamSink from outside. Implementation must be idempotent.

Meaning of value returned:

  • Poll::Pending : Pending to be closed, poll again in the future.
  • Poll::Ready(Err(error)) : Error happened.
  • Poll::Ready(Ok(Some(item))) : StreamSink wants to send more item as cleanup.
  • Poll::Ready(Ok(None)) : StreamSink is finalized.

Implementations on Foreign Types§

source§

impl<T, SendItem, RecvItem> StreamSink<SendItem, RecvItem> for &mut T
where T: StreamSink<SendItem, RecvItem> + ?Sized,

§

type Error = <T as StreamSink<SendItem, RecvItem>>::Error

source§

fn poll_stream_sink( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> State<SendItem, Self::Error>

source§

fn start_send(self: Pin<&mut Self>, item: RecvItem) -> Result<(), Self::Error>

source§

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<Option<SendItem>, Self::Error>>

source§

impl<T, SendItem, RecvItem> StreamSink<SendItem, RecvItem> for Pin<&mut T>
where T: StreamSink<SendItem, RecvItem> + ?Sized,

§

type Error = <T as StreamSink<SendItem, RecvItem>>::Error

source§

fn poll_stream_sink( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> State<SendItem, Self::Error>

source§

fn start_send(self: Pin<&mut Self>, item: RecvItem) -> Result<(), Self::Error>

source§

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<Option<SendItem>, Self::Error>>

Implementors§

source§

impl<'env, SI, RI, E> StreamSink<SI, RI> for LocalScopedStreamSink<'env, SI, RI, E>

§

type Error = E

source§

impl<'env, SI, RI, E> StreamSink<SI, RI> for ScopedStreamSink<'env, SI, RI, E>

§

type Error = E

source§

impl<S, R, Is, Ir, E> StreamSink<Is, Ir> for StreamSinkPair<S, R>
where S: Stream<Item = Result<Is, E>>, R: Sink<Ir, Error = E>,

§

type Error = E

source§

impl<SI, RI, E, T> StreamSink<SI, RI> for StreamSinkFallibleWrapper<SI, RI, E, T>
where T: Stream<Item = Result<SI, E>> + Sink<RI, Error = E> + ?Sized,

§

type Error = E

source§

impl<SI, RI, E, T> StreamSink<SI, RI> for StreamSinkWrapper<SI, RI, E, T>
where T: Stream<Item = SI> + Sink<RI, Error = E> + ?Sized,

§

type Error = E

source§

impl<T, F, SI, RI, E> StreamSink<SI, RI> for MapError<T, F>
where T: StreamSink<SI, RI>, F: FnMut(T::Error) -> E,

§

type Error = E

source§

impl<T, F, SI, RI, I> StreamSink<SI, RI> for MapRecv<T, F, I>
where T: StreamSink<SI, I>, F: FnMut(RI) -> I,

§

type Error = <T as StreamSink<SI, I>>::Error

source§

impl<T, F, SI, RI, I> StreamSink<SI, RI> for MapSend<T, F, I>
where T: StreamSink<I, RI>, F: FnMut(I) -> SI,

§

type Error = <T as StreamSink<I, RI>>::Error

source§

impl<T, SI, RI, E> StreamSink<SI, RI> for ErrorCast<T, E>
where T: StreamSink<SI, RI>, T::Error: Into<E>,

§

type Error = E

source§

impl<U, V, SI, II, RI> StreamSink<SI, RI> for Chain<U, V, II>
where U: StreamSink<II, RI>, V: StreamSink<SI, II, Error = U::Error>,

§

type Error = <U as StreamSink<II, RI>>::Error