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 Pointer(Pointer),
62 Other,
64}
65
66#[derive(Debug)]
68#[non_exhaustive]
69#[unstable(feature = "type_info", issue = "146922")]
70pub struct Tuple {
71 pub fields: &'static [Field],
73}
74
75#[derive(Debug)]
77#[non_exhaustive]
78#[unstable(feature = "type_info", issue = "146922")]
79pub struct Field {
80 pub ty: TypeId,
82 pub offset: usize,
84}
85
86#[derive(Debug)]
88#[non_exhaustive]
89#[unstable(feature = "type_info", issue = "146922")]
90pub struct Array {
91 pub element_ty: TypeId,
93 pub len: usize,
95}
96
97#[derive(Debug)]
99#[non_exhaustive]
100#[unstable(feature = "type_info", issue = "146922")]
101pub struct Bool {
102 }
104
105#[derive(Debug)]
107#[non_exhaustive]
108#[unstable(feature = "type_info", issue = "146922")]
109pub struct Char {
110 }
112
113#[derive(Debug)]
115#[non_exhaustive]
116#[unstable(feature = "type_info", issue = "146922")]
117pub struct Int {
118 pub bits: u32,
120 pub signed: bool,
122}
123
124#[derive(Debug)]
126#[non_exhaustive]
127#[unstable(feature = "type_info", issue = "146922")]
128pub struct Float {
129 pub bits: u32,
131}
132
133#[derive(Debug)]
135#[non_exhaustive]
136#[unstable(feature = "type_info", issue = "146922")]
137pub struct Str {
138 }
140
141#[derive(Debug)]
143#[non_exhaustive]
144#[unstable(feature = "type_info", issue = "146922")]
145pub struct Reference {
146 pub pointee: TypeId,
148 pub mutable: bool,
150}
151
152#[derive(Debug)]
154#[non_exhaustive]
155#[unstable(feature = "type_info", issue = "146922")]
156pub struct Pointer {
157 pub pointee: TypeId,
159 pub mutable: bool,
161}