1pub use std::borrow::Cow;
2
3#[derive(Hash, Debug, PartialEq, Eq, Clone)]
5pub struct TypeId(TypeIdInner);
6
7impl TypeId {
8 pub fn for_type<T: 'static + ?Sized>() -> Self {
10 TypeId(TypeIdInner::Type(std::any::TypeId::of::<T>()))
11 }
12
13 pub fn for_variant<T, S>(variant_name: S) -> Self
18 where
19 T: 'static + ?Sized,
20 S: Into<Cow<'static, str>>,
21 {
22 TypeId(TypeIdInner::Variant {
23 parent_enum: std::any::TypeId::of::<T>(),
24 variant_name: variant_name.into(),
25 })
26 }
27}
28
29#[derive(Hash, Debug, PartialEq, Eq, Clone)]
30pub(super) enum TypeIdInner {
31 Type(std::any::TypeId),
32
33 Variant {
34 parent_enum: std::any::TypeId,
35 variant_name: Cow<'static, str>,
36 },
37}