pub struct Cage<'life, Z: Zonbi<'life>> { /* private fields */ }
Expand description
Holds a Zonbi
with the 'life
lifetime and can be casted into a dyn AnyZonbi
.
This is done because it forbids to have a lower-lifetimed mutable reference to the zonbi, preventing a possible use-after-free reference. See this comment for more.
Implementations§
Source§impl<'life, Z: Zonbi<'life>> Cage<'life, Z>
impl<'life, Z: Zonbi<'life>> Cage<'life, Z>
Sourcepub fn new(val: Z) -> Self
pub fn new(val: Z) -> Self
Creates a new Cage
for a zonbi.
Examples found in repository?
examples/type_map.rs (line 25)
19fn with_zonbi<'a>(a: &'a NonCopyI32) {
20 let my_struct = MyStruct { val: a };
21
22 let mut type_map: HashMap<ZonbiId, Box<dyn AnyZonbi<'a>>> = HashMap::new();
23 let id = ZonbiId::of::<MyStruct>();
24
25 type_map.insert(id, Box::new(Cage::new(my_struct)));
26
27 let r: &MyStruct<'a> = type_map[&id].downcast_ref::<MyStruct<'a>>().unwrap();
28 assert_eq!(r.val, &NonCopyI32(42));
29 println!("{:?}", r.val);
30}
Sourcepub fn into_inner(self) -> Z::Casted
pub fn into_inner(self) -> Z::Casted
Returns the inner zonbi of this cage with a lifetime of 'life
Trait Implementations§
Auto Trait Implementations§
impl<'life, Z> Freeze for Cage<'life, Z>where
Z: Freeze,
impl<'life, Z> RefUnwindSafe for Cage<'life, Z>where
Z: RefUnwindSafe,
impl<'life, Z> Send for Cage<'life, Z>where
Z: Send,
impl<'life, Z> Sync for Cage<'life, Z>where
Z: Sync,
impl<'life, Z> Unpin for Cage<'life, Z>where
Z: Unpin,
impl<'life, Z> UnwindSafe for Cage<'life, Z>where
Z: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more