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 Slice(Slice),
50 DynTrait(DynTrait),
52 Bool(Bool),
54 Char(Char),
56 Int(Int),
58 Float(Float),
60 Str(Str),
62 Reference(Reference),
64 Pointer(Pointer),
66 Other,
68}
69
70#[derive(Debug)]
72#[non_exhaustive]
73#[unstable(feature = "type_info", issue = "146922")]
74pub struct Tuple {
75 pub fields: &'static [Field],
77}
78
79#[derive(Debug)]
81#[non_exhaustive]
82#[unstable(feature = "type_info", issue = "146922")]
83pub struct Field {
84 pub ty: TypeId,
86 pub offset: usize,
88}
89
90#[derive(Debug)]
92#[non_exhaustive]
93#[unstable(feature = "type_info", issue = "146922")]
94pub struct Array {
95 pub element_ty: TypeId,
97 pub len: usize,
99}
100
101#[derive(Debug)]
103#[non_exhaustive]
104#[unstable(feature = "type_info", issue = "146922")]
105pub struct Slice {
106 pub element_ty: TypeId,
108}
109
110#[derive(Debug)]
113#[non_exhaustive]
114#[unstable(feature = "type_info", issue = "146922")]
115pub struct DynTrait {
116 pub predicates: &'static [DynTraitPredicate],
118}
119
120#[derive(Debug)]
122#[non_exhaustive]
123#[unstable(feature = "type_info", issue = "146922")]
124pub struct DynTraitPredicate {
125 pub trait_ty: Trait,
127}
128
129#[derive(Debug)]
131#[non_exhaustive]
132#[unstable(feature = "type_info", issue = "146922")]
133pub struct Trait {
134 pub ty: TypeId,
136 pub is_auto: bool,
138}
139
140#[derive(Debug)]
142#[non_exhaustive]
143#[unstable(feature = "type_info", issue = "146922")]
144pub struct Bool {
145 }
147
148#[derive(Debug)]
150#[non_exhaustive]
151#[unstable(feature = "type_info", issue = "146922")]
152pub struct Char {
153 }
155
156#[derive(Debug)]
158#[non_exhaustive]
159#[unstable(feature = "type_info", issue = "146922")]
160pub struct Int {
161 pub bits: u32,
163 pub signed: bool,
165}
166
167#[derive(Debug)]
169#[non_exhaustive]
170#[unstable(feature = "type_info", issue = "146922")]
171pub struct Float {
172 pub bits: u32,
174}
175
176#[derive(Debug)]
178#[non_exhaustive]
179#[unstable(feature = "type_info", issue = "146922")]
180pub struct Str {
181 }
183
184#[derive(Debug)]
186#[non_exhaustive]
187#[unstable(feature = "type_info", issue = "146922")]
188pub struct Reference {
189 pub pointee: TypeId,
191 pub mutable: bool,
193}
194
195#[derive(Debug)]
197#[non_exhaustive]
198#[unstable(feature = "type_info", issue = "146922")]
199pub struct Pointer {
200 pub pointee: TypeId,
202 pub mutable: bool,
204}