Trait DropStreamExt

Source
pub trait DropStreamExt<U: FnOnce()>: Stream + Sized {
    // Required method
    fn on_drop(self, dropper: U) -> DropStream<Self, Self::Item, U>;
}

Required Methods§

Source

fn on_drop(self, dropper: U) -> DropStream<Self, Self::Item, U>

Wraps the stream with a closure that is called once it is dropped. ex:

use std::task::Poll;
use futures::{stream::repeat, Stream};
use drop_stream::DropStreamExt;

let some_stream = repeat(true);

let mut has_run = false;
let has_run_ref = &mut has_run;
let drop_stream = some_stream.on_drop(move || {
    *has_run_ref = true;
    println!("Stream has been dropped!")
});

let mut drop_stream = Box::pin(drop_stream);

// Some stream work and polling...

drop(drop_stream); // Runs the closure
assert!(has_run);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T, U: FnOnce()> DropStreamExt<U> for T
where T: Stream + Sized,