1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use std::any::TypeId;

#[repr(C)]
pub struct TaggedObject<T> {
  type_id: TypeId,
  pub(crate) object: Option<T>,
}

impl<T: 'static> TaggedObject<T> {
  pub fn new(object: T) -> Self {
    TaggedObject {
      type_id: TypeId::of::<T>(),
      object: Some(object),
    }
  }
}