use std::collections::HashMap;
use zonbi::{AnyZonbi, Cage, Zonbi, ZonbiId};
#[derive(Debug, PartialEq)]
struct NonCopyI32(i32);
#[derive(Zonbi)]
struct MyStruct<'a> {
val: &'a NonCopyI32,
}
fn main() {
let a = NonCopyI32(42);
with_zonbi(&a);
}
fn with_zonbi<'a>(a: &'a NonCopyI32) {
let my_struct = MyStruct { val: a };
let mut type_map: HashMap<ZonbiId, Box<dyn AnyZonbi<'a>>> = HashMap::new();
let id = ZonbiId::of::<MyStruct>();
type_map.insert(id, Box::new(Cage::new(my_struct)));
let r: &MyStruct<'a> = type_map[&id].downcast_ref::<MyStruct<'a>>().unwrap();
assert_eq!(r.val, &NonCopyI32(42));
println!("{:?}", r.val);
}