1use crate::any::TypeId;
5use crate::intrinsics::type_of;
6
7#[derive(Debug)]
9#[non_exhaustive]
10#[lang = "type_info"]
11#[unstable(feature = "type_info", issue = "146922")]
12pub struct Type {
13 pub kind: TypeKind,
15 pub size: Option<usize>,
17}
18
19impl TypeId {
20 #[unstable(feature = "type_info", issue = "146922")]
23 #[rustc_const_unstable(feature = "type_info", issue = "146922")]
24 pub const fn info(self) -> Type {
25 type_of(self)
26 }
27}
28
29impl Type {
30 #[unstable(feature = "type_info", issue = "146922")]
32 #[rustc_const_unstable(feature = "type_info", issue = "146922")]
33 pub const fn of<T: ?Sized + 'static>() -> Self {
35 const { TypeId::of::<T>().info() }
36 }
37}
38
39#[derive(Debug)]
41#[non_exhaustive]
42#[unstable(feature = "type_info", issue = "146922")]
43pub enum TypeKind {
44 Tuple(Tuple),
46 Array(Array),
48 Leaf,
51 Other,
53}
54
55#[derive(Debug)]
57#[non_exhaustive]
58#[unstable(feature = "type_info", issue = "146922")]
59pub struct Tuple {
60 pub fields: &'static [Field],
62}
63
64#[derive(Debug)]
66#[non_exhaustive]
67#[unstable(feature = "type_info", issue = "146922")]
68pub struct Field {
69 pub ty: TypeId,
71 pub offset: usize,
73}
74
75#[derive(Debug)]
77#[non_exhaustive]
78#[unstable(feature = "type_info", issue = "146922")]
79pub struct Array {
80 pub element_ty: TypeId,
82 pub len: usize,
84}