Trait AnyZonbi

Source
pub trait AnyZonbi<'life>: Sealed + 'life {
    // Required methods
    fn zonbi_id(&self) -> ZonbiId;
    unsafe fn get_raw(&self) -> *const ();
    unsafe fn get_raw_mut(&mut self) -> *mut ();
}
Expand description

The trait implemented by Cage to blur its generic Zonbi.

Required Methods§

Source

fn zonbi_id(&self) -> ZonbiId

Returns the ZonbiId of this erased type.

This needs a shared reference to self in order to be object-safe. If you have a concrete type without an instance of it, use Zonbi::zonbi_id instead.

Source

unsafe fn get_raw(&self) -> *const ()

Source

unsafe fn get_raw_mut(&mut self) -> *mut ()

Implementations§

Source§

impl<'life> dyn AnyZonbi<'life>

Source

pub fn represents<Z: Zonbi<'life>>(&self) -> bool

Returns true if the inner type represents the same as T, excluding its lifetimes.

Source

pub fn downcast_ref<Z: Zonbi<'life>>(&self) -> Option<&Z::Casted>

Returns a shared reference to the inner value with a lifetime of 'life if it represents the zonbi Z, or None if it doesn’t.

Examples found in repository?
examples/type_map.rs (line 27)
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}
Source

pub unsafe fn downcast_ref_unchecked<Z: Zonbi<'life>>(&self) -> &Z::Casted

Source

pub fn downcast_mut<Z: Zonbi<'life>>(&mut self) -> Option<&mut Z::Casted>

Returns an exclusive reference to the inner value with a lifetime of 'life if it represents the zonbi Z, or None if it doesn’t.

Source

pub unsafe fn downcast_mut_unchecked<Z: Zonbi<'life>>( &mut self, ) -> &mut Z::Casted

Implementors§

Source§

impl<'life, Z: Zonbi<'life>> AnyZonbi<'life> for Cage<'life, Z>