macro_rules! scoped_static {
($ref_value:expr) => { ... };
}Expand description
A safe way to create a ScopedRefGuard.
use scoped_static::scoped_static;
#[tokio::main]
async fn main() {
let concrete_value = Box::new(1.0);
let ref_value = &concrete_value;
let guard = scoped_static!(ref_value);
let lifted = guard.lift();
tokio::spawn(async move {
// Lifted is 'static so it can be moved into this closure that needs 'static
let value = **lifted + 1.0;
assert_eq!(value, 2.0);
// `lifted` is dropped here
})
.await
.unwrap();
// `guard` is dropped here
}