macro_rules! lifelink { ($lifelink:ident : $ty:ty = $thing:expr) => { ... }; }
Expand description
Safe helper macro for creating a Lifelink
value wrapping thing
. The lifetime
of this Lifelink
value will be managed by the Rust compiler, and the thing
passed in cannot be retrieved.
If you need a way to later retrieve ownership of the thing
value passed in, see
the unsafe Lifelink::new
constructor which this macro uses internally.
Example
use std::thread::spawn;
use std::sync::atomic::{AtomicUsize, Ordering};
use lifelink::{lifelink, Lifelink, RefCtor};
let answer = AtomicUsize::new(0);
lifelink!(lifelink: RefCtor<AtomicUsize> = &answer);
{
let guard = lifelink.get().unwrap();
assert_eq!(0, guard.load(Ordering::Relaxed));
guard.store(42, Ordering::Release);
}
assert_eq!(42, answer.load(Ordering::Acquire));