Trait s2n_quic::stream::SplittableStream
source · pub trait SplittableStream {
// Required method
fn split(self) -> (Option<ReceiveStream>, Option<SendStream>);
}
Expand description
A trait that enables a stream to split into a ReceiveStream
and SendStream
.
Note that if a stream is only allowed to send, then the receiving side will be None
.
The same is true for streams that are only allowed to receive: the sending side will be None
.
Required Methods§
sourcefn split(self) -> (Option<ReceiveStream>, Option<SendStream>)
fn split(self) -> (Option<ReceiveStream>, Option<SendStream>)
Splits the stream into ReceiveStream
and SendStream
halves
§Examples
let stream = connection.open_bidirectional_stream().await?;
let (recv, send) = s2n_quic::stream::SplittableStream::split(stream);
let mut recv = recv.expect("bidirectional streams have receiving sides");
let mut send = send.expect("bidirectional streams have sending sides");
tokio::spawn(async move {
let _ = send.send(Bytes::from_static(&[1, 2, 3])).await;
});
while let Some(chunk) = recv.receive().await? {
println!("received: {:?}", chunk);
}