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 Bool(Bool),
50 Char(Char),
52 Int(Int),
54 Float(Float),
56 Str(Str),
58 Reference(Reference),
60 Other,
62}
63
64#[derive(Debug)]
66#[non_exhaustive]
67#[unstable(feature = "type_info", issue = "146922")]
68pub struct Tuple {
69 pub fields: &'static [Field],
71}
72
73#[derive(Debug)]
75#[non_exhaustive]
76#[unstable(feature = "type_info", issue = "146922")]
77pub struct Field {
78 pub ty: TypeId,
80 pub offset: usize,
82}
83
84#[derive(Debug)]
86#[non_exhaustive]
87#[unstable(feature = "type_info", issue = "146922")]
88pub struct Array {
89 pub element_ty: TypeId,
91 pub len: usize,
93}
94
95#[derive(Debug)]
97#[non_exhaustive]
98#[unstable(feature = "type_info", issue = "146922")]
99pub struct Bool {
100 }
102
103#[derive(Debug)]
105#[non_exhaustive]
106#[unstable(feature = "type_info", issue = "146922")]
107pub struct Char {
108 }
110
111#[derive(Debug)]
113#[non_exhaustive]
114#[unstable(feature = "type_info", issue = "146922")]
115pub struct Int {
116 pub bit_width: usize,
118 pub signed: bool,
120}
121
122#[derive(Debug)]
124#[non_exhaustive]
125#[unstable(feature = "type_info", issue = "146922")]
126pub struct Float {
127 pub bit_width: usize,
129}
130
131#[derive(Debug)]
133#[non_exhaustive]
134#[unstable(feature = "type_info", issue = "146922")]
135pub struct Str {
136 }
138
139#[derive(Debug)]
141#[non_exhaustive]
142#[unstable(feature = "type_info", issue = "146922")]
143pub struct Reference {
144 pub pointee: TypeId,
146 pub mutable: bool,
148}