pub trait StreamExt {
// Provided methods
fn with_personality(self, personality: u16) -> WithPersonality<Self> ⓘ
where Self: Sized { ... }
fn with_cancel(self, token: CancelToken) -> WithCancel<Self> ⓘ
where Self: Sized { ... }
}Expand description
Extension trait for streams.
§Implementation
Extra data are passed down to runtime when the combinators are polled using
a custom Waker, and those data are single-threaded. This means
- when
Wakers are sent to other threads, the data will be lost. - when using a “sub-executor” like
FuturesUnordered, which also creates its own waker, the data will be lost.
So try to keep the path from the wrapped stream to runtime clean, something like this will generally work:
ⓘ
use std::vec::Vec;
use compio::runtime::{StreamExt, CancelToken};
use compio::net::TcpStream;
let input = TcpStream::connect("127.0.0.1:8000").await.unwrap();
let cancel = CancelToken::new();
let mut input_stream = input.read_multi(0).with_cancel(cancel.clone());
while let Some(buf) = input_stream.next().await {
let _ = buf.unwrap();
}Provided Methods§
Sourcefn with_personality(self, personality: u16) -> WithPersonality<Self> ⓘwhere
Self: Sized,
fn with_personality(self, personality: u16) -> WithPersonality<Self> ⓘwhere
Self: Sized,
Sets the personality for this stream.
This only takes effect on io-uring drivers and will be ignored on other ones.
Sourcefn with_cancel(self, token: CancelToken) -> WithCancel<Self> ⓘwhere
Self: Sized,
fn with_cancel(self, token: CancelToken) -> WithCancel<Self> ⓘwhere
Self: Sized,
Sets the cancel token for this stream.
If multiple CancelTokens are set, the innermost one (the one being
polled last) will take precedence.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".