Debian Codegraph @

third_party/rust/futures/tests/future_obj.rs

raw
1 use futures::future::{Future, FutureExt, FutureObj};
2 use futures::task::{Context, Poll};
3 use std::pin::Pin;
4
5 #[test]
6 fn dropping_does_not_segfault() {
7 FutureObj::new(async { String::new() }.boxed());
8 }
9
10 #[test]
11 fn dropping_drops_the_future() {
12 let mut times_dropped = 0;
13
14 struct Inc<'a>(&'a mut u32);
15
16 impl Future for Inc<'_> {
17 type Output = ();
18
19 fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<()> {
20 unimplemented!()
21 }
22 }
23
24 impl Drop for Inc<'_> {
25 fn drop(&mut self) {
26 *self.0 += 1;
27 }
28 }
29
30 FutureObj::new(Inc(&mut times_dropped).boxed());
31
32 assert_eq!(times_dropped, 1);
33 }