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 FnPtr(FnPtr),
80 Other,
82}
83
84#[derive(Debug)]
86#[non_exhaustive]
87#[unstable(feature = "type_info", issue = "146922")]
88pub struct Tuple {
89 pub fields: &'static [Field],
91}
92
93#[derive(Debug)]
95#[non_exhaustive]
96#[unstable(feature = "type_info", issue = "146922")]
97pub struct Field {
98 pub name: &'static str,
100 pub ty: TypeId,
102 pub offset: usize,
104}
105
106#[derive(Debug)]
108#[non_exhaustive]
109#[unstable(feature = "type_info", issue = "146922")]
110pub struct Array {
111 pub element_ty: TypeId,
113 pub len: usize,
115}
116
117#[derive(Debug)]
119#[non_exhaustive]
120#[unstable(feature = "type_info", issue = "146922")]
121pub struct Slice {
122 pub element_ty: TypeId,
124}
125
126#[derive(Debug)]
129#[non_exhaustive]
130#[unstable(feature = "type_info", issue = "146922")]
131pub struct DynTrait {
132 pub predicates: &'static [DynTraitPredicate],
134}
135
136#[derive(Debug)]
138#[non_exhaustive]
139#[unstable(feature = "type_info", issue = "146922")]
140pub struct DynTraitPredicate {
141 pub trait_ty: Trait,
143}
144
145#[derive(Debug)]
147#[non_exhaustive]
148#[unstable(feature = "type_info", issue = "146922")]
149pub struct Trait {
150 pub ty: TypeId,
152 pub is_auto: bool,
154}
155
156#[derive(Debug)]
158#[non_exhaustive]
159#[unstable(feature = "type_info", issue = "146922")]
160pub struct Struct {
161 pub generics: &'static [Generic],
163 pub fields: &'static [Field],
165 pub non_exhaustive: bool,
167}
168
169#[derive(Debug)]
171#[non_exhaustive]
172#[unstable(feature = "type_info", issue = "146922")]
173pub struct Union {
174 pub generics: &'static [Generic],
176 pub fields: &'static [Field],
178}
179
180#[derive(Debug)]
182#[non_exhaustive]
183#[unstable(feature = "type_info", issue = "146922")]
184pub struct Enum {
185 pub generics: &'static [Generic],
187 pub variants: &'static [Variant],
189 pub non_exhaustive: bool,
191}
192
193#[derive(Debug)]
195#[non_exhaustive]
196#[unstable(feature = "type_info", issue = "146922")]
197pub struct Variant {
198 pub name: &'static str,
200 pub fields: &'static [Field],
202 pub non_exhaustive: bool,
204}
205
206#[derive(Debug)]
208#[non_exhaustive]
209#[unstable(feature = "type_info", issue = "146922")]
210pub enum Generic {
211 Lifetime(Lifetime),
213 Type(GenericType),
215 Const(Const),
217}
218
219#[derive(Debug)]
221#[non_exhaustive]
222#[unstable(feature = "type_info", issue = "146922")]
223pub struct Lifetime {
224 }
226
227#[derive(Debug)]
229#[non_exhaustive]
230#[unstable(feature = "type_info", issue = "146922")]
231pub struct GenericType {
232 pub ty: TypeId,
234}
235
236#[derive(Debug)]
238#[non_exhaustive]
239#[unstable(feature = "type_info", issue = "146922")]
240pub struct Const {
241 pub ty: TypeId,
243}
244
245#[derive(Debug)]
247#[non_exhaustive]
248#[unstable(feature = "type_info", issue = "146922")]
249pub struct Bool {
250 }
252
253#[derive(Debug)]
255#[non_exhaustive]
256#[unstable(feature = "type_info", issue = "146922")]
257pub struct Char {
258 }
260
261#[derive(Debug)]
263#[non_exhaustive]
264#[unstable(feature = "type_info", issue = "146922")]
265pub struct Int {
266 pub bits: u32,
268 pub signed: bool,
270}
271
272#[derive(Debug)]
274#[non_exhaustive]
275#[unstable(feature = "type_info", issue = "146922")]
276pub struct Float {
277 pub bits: u32,
279}
280
281#[derive(Debug)]
283#[non_exhaustive]
284#[unstable(feature = "type_info", issue = "146922")]
285pub struct Str {
286 }
288
289#[derive(Debug)]
291#[non_exhaustive]
292#[unstable(feature = "type_info", issue = "146922")]
293pub struct Reference {
294 pub pointee: TypeId,
296 pub mutable: bool,
298}
299
300#[derive(Debug)]
302#[non_exhaustive]
303#[unstable(feature = "type_info", issue = "146922")]
304pub struct Pointer {
305 pub pointee: TypeId,
307 pub mutable: bool,
309}
310
311#[derive(Debug)]
312#[unstable(feature = "type_info", issue = "146922")]
313pub struct FnPtr {
315 pub unsafety: bool,
317
318 pub abi: Abi,
320
321 pub inputs: &'static [TypeId],
323
324 pub output: TypeId,
326
327 pub variadic: bool,
329}
330
331#[derive(Debug, Default)]
332#[non_exhaustive]
333#[unstable(feature = "type_info", issue = "146922")]
334pub enum Abi {
336 Named(&'static str),
338
339 #[default]
341 ExternRust,
342
343 ExternC,
345}