macro_rules! give_opaque_static_form {
($value:expr) => { ... };
}Expand description
Wrap opaque typed value to implement StaticForm.
This macro generates a #[repr(transparent)] wrapper struct
that implements StaticForm. The resulting wrapper is also
an opaque type.
Use the value.0 accessor to get the original value.
ยงExamples
use dungeon_cell::give_opaque_static_form;
use dungeon_cell::lifetime_type_id::{LifetimeTypeId, StaticForm};
let mut a = 42;
let b = &mut a;
// closures have an opaque type
let x = || *b += 1;
// wrap the closure so it works with of_value
let mut z = give_opaque_static_form!(x);
// we can still access the closure.
z();
// the type ID of the closure isn't the same as a i32
assert_ne!(of_value(&z), of_value(&0));
// calling the closure changed the variable so it has a lifetime
assert_eq!(a, 43);
fn of_value<'a, T: StaticForm<'a>>(_: &T) -> LifetimeTypeId<'a> {
LifetimeTypeId::of::<T>()
}