Struct drop_stream::DropStream
source · 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
sourceimpl<S: Stream<Item = T> + Unpin, T, U: FnOnce() + Unpin> Stream for DropStream<S, T, U>
impl<S: Stream<Item = T> + Unpin, T, U: FnOnce() + Unpin> Stream for DropStream<S, T, U>
type Item = T
type Item = T
Values yielded by the stream.
Auto Trait Implementations
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>where
S: Send,
U: Send,
impl<S, T, U> Sync for DropStream<S, T, U>where
S: Sync,
U: Sync,
impl<S, T, U> Unpin for DropStream<S, T, U>
impl<S, T, U> UnwindSafe for DropStream<S, T, U>where
S: UnwindSafe,
U: 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