summaryrefslogtreecommitdiffstats
path: root/vendor/futures/tests/future_obj.rs
blob: 0e5253464e59743e94ff8b1599e2395f50b3bffe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use futures::future::{Future, FutureExt, FutureObj};
use futures::task::{Context, Poll};
use std::pin::Pin;

#[test]
fn dropping_does_not_segfault() {
    FutureObj::new(async { String::new() }.boxed());
}

#[test]
fn dropping_drops_the_future() {
    let mut times_dropped = 0;

    struct Inc<'a>(&'a mut u32);

    impl Future for Inc<'_> {
        type Output = ();

        fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<()> {
            unimplemented!()
        }
    }

    impl Drop for Inc<'_> {
        fn drop(&mut self) {
            *self.0 += 1;
        }
    }

    FutureObj::new(Inc(&mut times_dropped).boxed());

    assert_eq!(times_dropped, 1);
}