Trait scoped_stream_sink::StreamSink
source · 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§
Required Methods§
sourcefn poll_stream_sink(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> State<SendItem, Self::Error>
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.
sourcefn start_send(self: Pin<&mut Self>, item: RecvItem) -> Result<(), Self::Error>
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.
sourcefn poll_close(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<Option<SendItem>, Self::Error>>
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.