1use crate::any::TypeId;
5use crate::intrinsics::{type_id, 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")]
39 #[rustc_const_unstable(feature = "type_info", issue = "146922")]
40 pub const fn of<T: ?Sized>() -> Self {
41 const { type_id::<T>().info() }
42 }
43}
44
45#[derive(Debug)]
47#[non_exhaustive]
48#[unstable(feature = "type_info", issue = "146922")]
49pub enum TypeKind {
50 Tuple(Tuple),
52 Array(Array),
54 Slice(Slice),
56 DynTrait(DynTrait),
58 Struct(Struct),
60 Enum(Enum),
62 Union(Union),
64 Bool(Bool),
66 Char(Char),
68 Int(Int),
70 Float(Float),
72 Str(Str),
74 Reference(Reference),
76 Pointer(Pointer),
78 Other,
80}
81
82#[derive(Debug)]
84#[non_exhaustive]
85#[unstable(feature = "type_info", issue = "146922")]
86pub struct Tuple {
87 pub fields: &'static [Field],
89}
90
91#[derive(Debug)]
93#[non_exhaustive]
94#[unstable(feature = "type_info", issue = "146922")]
95pub struct Field {
96 pub name: &'static str,
98 pub ty: TypeId,
100 pub offset: usize,
102}
103
104#[derive(Debug)]
106#[non_exhaustive]
107#[unstable(feature = "type_info", issue = "146922")]
108pub struct Array {
109 pub element_ty: TypeId,
111 pub len: usize,
113}
114
115#[derive(Debug)]
117#[non_exhaustive]
118#[unstable(feature = "type_info", issue = "146922")]
119pub struct Slice {
120 pub element_ty: TypeId,
122}
123
124#[derive(Debug)]
127#[non_exhaustive]
128#[unstable(feature = "type_info", issue = "146922")]
129pub struct DynTrait {
130 pub predicates: &'static [DynTraitPredicate],
132}
133
134#[derive(Debug)]
136#[non_exhaustive]
137#[unstable(feature = "type_info", issue = "146922")]
138pub struct DynTraitPredicate {
139 pub trait_ty: Trait,
141}
142
143#[derive(Debug)]
145#[non_exhaustive]
146#[unstable(feature = "type_info", issue = "146922")]
147pub struct Trait {
148 pub ty: TypeId,
150 pub is_auto: bool,
152}
153
154#[derive(Debug)]
156#[non_exhaustive]
157#[unstable(feature = "type_info", issue = "146922")]
158pub struct Struct {
159 pub generics: &'static [Generic],
161 pub fields: &'static [Field],
163 pub non_exhaustive: bool,
165}
166
167#[derive(Debug)]
169#[non_exhaustive]
170#[unstable(feature = "type_info", issue = "146922")]
171pub struct Union {
172 pub generics: &'static [Generic],
174 pub fields: &'static [Field],
176}
177
178#[derive(Debug)]
180#[non_exhaustive]
181#[unstable(feature = "type_info", issue = "146922")]
182pub struct Enum {
183 pub generics: &'static [Generic],
185 pub variants: &'static [Variant],
187 pub non_exhaustive: bool,
189}
190
191#[derive(Debug)]
193#[non_exhaustive]
194#[unstable(feature = "type_info", issue = "146922")]
195pub struct Variant {
196 pub name: &'static str,
198 pub fields: &'static [Field],
200 pub non_exhaustive: bool,
202}
203
204#[derive(Debug)]
206#[non_exhaustive]
207#[unstable(feature = "type_info", issue = "146922")]
208pub enum Generic {
209 Lifetime(Lifetime),
211 Type(GenericType),
213 Const(Const),
215}
216
217#[derive(Debug)]
219#[non_exhaustive]
220#[unstable(feature = "type_info", issue = "146922")]
221pub struct Lifetime {
222 }
224
225#[derive(Debug)]
227#[non_exhaustive]
228#[unstable(feature = "type_info", issue = "146922")]
229pub struct GenericType {
230 pub ty: TypeId,
232}
233
234#[derive(Debug)]
236#[non_exhaustive]
237#[unstable(feature = "type_info", issue = "146922")]
238pub struct Const {
239 pub ty: TypeId,
241}
242
243#[derive(Debug)]
245#[non_exhaustive]
246#[unstable(feature = "type_info", issue = "146922")]
247pub struct Bool {
248 }
250
251#[derive(Debug)]
253#[non_exhaustive]
254#[unstable(feature = "type_info", issue = "146922")]
255pub struct Char {
256 }
258
259#[derive(Debug)]
261#[non_exhaustive]
262#[unstable(feature = "type_info", issue = "146922")]
263pub struct Int {
264 pub bits: u32,
266 pub signed: bool,
268}
269
270#[derive(Debug)]
272#[non_exhaustive]
273#[unstable(feature = "type_info", issue = "146922")]
274pub struct Float {
275 pub bits: u32,
277}
278
279#[derive(Debug)]
281#[non_exhaustive]
282#[unstable(feature = "type_info", issue = "146922")]
283pub struct Str {
284 }
286
287#[derive(Debug)]
289#[non_exhaustive]
290#[unstable(feature = "type_info", issue = "146922")]
291pub struct Reference {
292 pub pointee: TypeId,
294 pub mutable: bool,
296}
297
298#[derive(Debug)]
300#[non_exhaustive]
301#[unstable(feature = "type_info", issue = "146922")]
302pub struct Pointer {
303 pub pointee: TypeId,
305 pub mutable: bool,
307}