pub struct DropStream<S: Stream<Item = T>, T, U: FnOnce()> { /* private fields */ }
Expand description
A stream that wraps another stream with a closure that is called once it is dropped. Very useful for libraries that use streams for data transfer and you need to connect when the opposite site drops the connection, thus dropping the stream.
Example
use futures::Stream;
use drop_stream::DropStream;
let test_stream = futures::stream::repeat(true);
{
let wrapped_stream = DropStream::new(test_stream, move || {
println!("Stream has been dropped!");
});
let mut wrapped_stream = Box::pin(wrapped_stream);
let waker = futures::task::noop_waker();
let mut context = futures::task::Context::from_waker(&waker);
assert_eq!(
wrapped_stream.as_mut().poll_next(&mut context),
std::task::Poll::Ready(Some(true))
);
}
Implementations§
Trait Implementations§
Source§impl<S: Stream<Item = T>, T, U: FnOnce()> Stream for DropStream<S, T, U>
impl<S: Stream<Item = T>, T, U: FnOnce()> Stream for DropStream<S, T, U>
impl<'pin, S: Stream<Item = T>, T, U: FnOnce()> Unpin for DropStream<S, T, U>where
PinnedFieldsOf<__DropStream<'pin, S, T, U>>: Unpin,
Auto Trait Implementations§
impl<S, T, U> Freeze for DropStream<S, T, U>
impl<S, T, U> RefUnwindSafe for DropStream<S, T, U>where
S: RefUnwindSafe,
U: RefUnwindSafe,
impl<S, T, U> Send for DropStream<S, T, U>
impl<S, T, U> Sync for DropStream<S, T, U>
impl<S, T, U> UnwindSafe for DropStream<S, T, U>where
S: UnwindSafe,
U: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more