go_away/
type_id.rs

1pub use std::borrow::Cow;
2
3/// A type identifier - used to deduplicate types in the output
4#[derive(Hash, Debug, PartialEq, Eq, Clone)]
5pub struct TypeId(TypeIdInner);
6
7impl TypeId {
8    /// Construct a `TypeId` for a given rust type
9    pub fn for_type<T: 'static + ?Sized>() -> Self {
10        TypeId(TypeIdInner::Type(std::any::TypeId::of::<T>()))
11    }
12
13    /// Construct a `TypeId` for a variant of a rust enum.
14    ///
15    /// This needs specific support beacuse our output needs types that
16    /// don't exist directly in rust.
17    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}