@@ -2,7 +2,7 @@ use crate::{ListInfo, MapInfo, Reflect, StructInfo, TupleInfo, TupleStructInfo};
2
2
use std:: any:: TypeId ;
3
3
use std:: borrow:: { Borrow , Cow } ;
4
4
5
- /// Compile-time type information for various object types
5
+ /// Compile-time type information for various reflected types
6
6
#[ derive( Debug , Clone ) ]
7
7
pub enum TypeInfo {
8
8
Struct ( StructInfo ) ,
@@ -17,6 +17,34 @@ pub enum TypeInfo {
17
17
Dynamic ( DynamicInfo ) ,
18
18
}
19
19
20
+ impl TypeInfo {
21
+ /// The name of the reflected type
22
+ pub fn type_name ( & self ) -> & str {
23
+ match self {
24
+ Self :: Struct ( info) => info. type_name ( ) ,
25
+ Self :: TupleStruct ( info) => info. type_name ( ) ,
26
+ Self :: Tuple ( info) => info. type_name ( ) ,
27
+ Self :: List ( info) => info. type_name ( ) ,
28
+ Self :: Map ( info) => info. type_name ( ) ,
29
+ Self :: Value ( info) => info. type_name ( ) ,
30
+ Self :: Dynamic ( info) => info. type_name ( ) ,
31
+ }
32
+ }
33
+
34
+ /// The `TypeId` of the reflected type
35
+ pub fn type_id ( & self ) -> TypeId {
36
+ match self {
37
+ Self :: Struct ( info) => info. type_id ( ) ,
38
+ Self :: TupleStruct ( info) => info. type_id ( ) ,
39
+ Self :: Tuple ( info) => info. type_id ( ) ,
40
+ Self :: List ( info) => info. type_id ( ) ,
41
+ Self :: Map ( info) => info. type_id ( ) ,
42
+ Self :: Value ( info) => info. type_id ( ) ,
43
+ Self :: Dynamic ( info) => info. type_id ( ) ,
44
+ }
45
+ }
46
+ }
47
+
20
48
/// A container for compile-time info related to general value types, including primitives
21
49
#[ derive( Debug , Clone ) ]
22
50
pub struct ValueInfo {
0 commit comments