Skip to main content

leak_playground_std/
future.rs

1//! # Examples
2//!
3//! `Forget` future with internal unforget logic.
4//!
5//! **Currently emits "higher-ranked lifetime error", instead of compiling**
6//!
7//! ```ignore
8//! use leak_playground_std::marker::{Forget, Unforget};
9//! fn _internal_unforget_future() -> impl std::future::Future<Output = ()> + Forget {
10//!     async {
11//!         let num = std::hint::black_box(0);
12//!         let bor = Unforget::new(&num);
13//!         let () = std::future::pending().await;
14//!         assert_eq!(**bor, 0);
15//!     }
16//! }
17//! ```
18//!
19//! `Forget` future with `JoinGuard`s. This is fine because of the pin's [drop
20//! guarantee](https://doc.rust-lang.org/1.75.0/std/pin/index.html#drop-guarantee).
21//!
22//! **Currently emits "higher-ranked lifetime error", instead of compiling**
23//!
24//! ```ignore
25//! use leak_playground_std::thread;
26//! use leak_playground_std::marker::Forget;
27//! fn _internal_join_guard_future() -> impl std::future::Future<Output = ()> + Forget {
28//!     async {
29//!         let local = 42;
30//!         let thrd = thread::spawn_scoped({
31//!             let local = &local;
32//!             move || {
33//!                 let _inner_local = local;
34//!             }
35//!         });
36//!         let () = std::future::pending().await;
37//!         drop(thrd);
38//!     }
39//! }
40//! ```
41//!
42//! `!Forget` future with external unforget logic
43//!
44//! **Currently emits "higher-ranked lifetime error", instead of something about unimplemented `Forget`**
45//!
46//! ```compile_fail
47//! use leak_playground_std::marker::{Forget, Unforget};
48//! fn _external_unforget_future<'a>(num: &'a i32) -> impl std::future::Future<Output = ()> + Forget + 'a {
49//!     async move {
50//!         let bor = Unforget::new(num);
51//!         let () = std::future::pending().await;
52//!         assert_eq!(**bor, 0);
53//!     }
54//! }
55//! ```
56//!