pub struct ZonbiId(/* private fields */);
Expand description
A ZonbiId
represents a globally unique identifier for the 'static
version of a type.
Because ZonbiId
relies on rust’s TypeId
, please keep their warning in mind
that the hashes and ordering will vary between Rust releases. Beware
of relying on them inside of your code!
Implementations§
Source§impl ZonbiId
impl ZonbiId
Sourcepub fn of<'life, Z: Zonbi<'life>>() -> ZonbiId
pub fn of<'life, Z: Zonbi<'life>>() -> ZonbiId
Returns the ZonbiId
of the given generic type.
This is equal to the TypeId
of the 'static
version of the type.
Examples found in repository?
examples/type_map.rs (line 23)
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}
Trait Implementations§
Source§impl Ord for ZonbiId
impl Ord for ZonbiId
Source§impl PartialOrd for ZonbiId
impl PartialOrd for ZonbiId
impl Copy for ZonbiId
impl Eq for ZonbiId
impl StructuralPartialEq for ZonbiId
Auto Trait Implementations§
impl Freeze for ZonbiId
impl RefUnwindSafe for ZonbiId
impl Send for ZonbiId
impl Sync for ZonbiId
impl Unpin for ZonbiId
impl UnwindSafe for ZonbiId
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