Struct tokio_stream::StreamNotifyClose
source · [−]pub struct StreamNotifyClose<S> { /* private fields */ }
Expand description
A Stream
that wraps the values in an Option
.
Whenever the wrapped stream yields an item, this stream yields that item
wrapped in Some
. When the inner stream ends, then this stream first
yields a None
item, and then this stream will also end.
Example
Using StreamNotifyClose
to handle closed streams with StreamMap
.
use tokio_stream::{StreamExt, StreamMap, StreamNotifyClose};
#[tokio::main]
async fn main() {
let mut map = StreamMap::new();
let stream = StreamNotifyClose::new(tokio_stream::iter(vec![0, 1]));
let stream2 = StreamNotifyClose::new(tokio_stream::iter(vec![0, 1]));
map.insert(0, stream);
map.insert(1, stream2);
while let Some((key, val)) = map.next().await {
match val {
Some(val) => println!("got {val:?} from stream {key:?}"),
None => println!("stream {key:?} closed"),
}
}
}
Implementations
sourceimpl<S> StreamNotifyClose<S>
impl<S> StreamNotifyClose<S>
sourcepub fn into_inner(self) -> Option<S>
pub fn into_inner(self) -> Option<S>
Get back the inner Stream
.
Returns None
if the stream has reached its end.
Trait Implementations
sourceimpl<S> Stream for StreamNotifyClose<S>where
S: Stream,
impl<S> Stream for StreamNotifyClose<S>where
S: Stream,
impl<'__pin, S> Unpin for StreamNotifyClose<S>where
__Origin<'__pin, S>: Unpin,
Auto Trait Implementations
impl<S> RefUnwindSafe for StreamNotifyClose<S>where
S: RefUnwindSafe,
impl<S> Send for StreamNotifyClose<S>where
S: Send,
impl<S> Sync for StreamNotifyClose<S>where
S: Sync,
impl<S> UnwindSafe for StreamNotifyClose<S>where
S: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more