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))):StreamSinkwants to send more item as cleanup.Poll::Ready(Ok(None)):StreamSinkis finalized.
Implementations on Foreign Types§
Source§impl<T, SendItem, RecvItem> StreamSink<SendItem, RecvItem> for &mut Twhere
T: StreamSink<SendItem, RecvItem> + ?Sized,
impl<T, SendItem, RecvItem> StreamSink<SendItem, RecvItem> for &mut Twhere
T: StreamSink<SendItem, RecvItem> + ?Sized,
type Error = <T as StreamSink<SendItem, RecvItem>>::Error
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>>
Source§impl<T, SendItem, RecvItem> StreamSink<SendItem, RecvItem> for Pin<&mut T>where
T: StreamSink<SendItem, RecvItem> + ?Sized,
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
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>>
Implementors§
Source§impl<'env, SI, RI, E> StreamSink<SI, RI> for LocalScopedStreamSink<'env, SI, RI, E>
impl<'env, SI, RI, E> StreamSink<SI, RI> for LocalScopedStreamSink<'env, SI, RI, E>
Source§impl<'env, SI, RI, E> StreamSink<SI, RI> for ScopedStreamSink<'env, SI, RI, E>
Available on crate feature std only.
impl<'env, SI, RI, E> StreamSink<SI, RI> for ScopedStreamSink<'env, SI, RI, E>
Available on crate feature
std only.