@@ -13,83 +13,8 @@ In the future when `min_specialization` is stabilized we could use it instead an
13
13
the `'static` bound altogether.
14
14
*/
15
15
16
- // Use consts to match a type with a conversion fn
17
- #[ cfg( all( srcbuild, const_type_id) ) ]
18
- pub ( super ) fn from_any < ' v , T : ?Sized + ' static > (
19
- value : & ' v T ,
20
- ) -> Option < crate :: kv:: value:: internal:: Primitive < ' v > > {
21
- use std:: any:: TypeId ;
22
-
23
- use crate :: kv:: value:: internal:: Primitive ;
24
-
25
- macro_rules! to_primitive {
26
- ( $( $ty: ty : ( $const_ident: ident, $option_ident: ident) , ) * ) => {
27
- trait ToPrimitive
28
- where
29
- Self : ' static ,
30
- {
31
- const CALL : fn ( & Self ) -> Option <Primitive > = {
32
- $(
33
- const $const_ident: TypeId = TypeId :: of:: <$ty>( ) ;
34
- const $option_ident: TypeId = TypeId :: of:: <Option <$ty>>( ) ;
35
- ) ;*
36
-
37
- match TypeId :: of:: <Self >( ) {
38
- $(
39
- $const_ident => |v| Some ( Primitive :: from( unsafe { * ( v as * const Self as * const $ty) } ) ) ,
40
- $option_ident => |v| Some ( {
41
- let v = unsafe { * ( v as * const Self as * const Option <$ty>) } ;
42
- match v {
43
- Some ( v) => Primitive :: from( v) ,
44
- None => Primitive :: None ,
45
- }
46
- } ) ,
47
- ) *
48
-
49
- _ => |_| None ,
50
- }
51
- } ;
52
-
53
- fn to_primitive( & self ) -> Option <Primitive > {
54
- ( Self :: CALL ) ( self )
55
- }
56
- }
57
-
58
- impl <T : ?Sized + ' static > ToPrimitive for T { }
59
- }
60
- }
61
-
62
- // NOTE: The types here *must* match the ones used below when `const_type_id` is not available
63
- to_primitive ! [
64
- usize : ( USIZE , OPTION_USIZE ) ,
65
- u8 : ( U8 , OPTION_U8 ) ,
66
- u16 : ( U16 , OPTION_U16 ) ,
67
- u32 : ( U32 , OPTION_U32 ) ,
68
- u64 : ( U64 , OPTION_U64 ) ,
69
-
70
- isize : ( ISIZE , OPTION_ISIZE ) ,
71
- i8 : ( I8 , OPTION_I8 ) ,
72
- i16 : ( I16 , OPTION_I16 ) ,
73
- i32 : ( I32 , OPTION_I32 ) ,
74
- i64 : ( I64 , OPTION_I64 ) ,
75
-
76
- f32 : ( F32 , OPTION_F32 ) ,
77
- f64 : ( F64 , OPTION_F64 ) ,
78
-
79
- char : ( CHAR , OPTION_CHAR ) ,
80
- bool : ( BOOL , OPTION_BOOL ) ,
81
- & ' static str : ( STR , OPTION_STR ) ,
82
- ] ;
83
-
84
- value. to_primitive ( )
85
- }
86
-
87
- #[ cfg( all( not( src_build) , const_type_id) ) ]
88
- #[ allow( dead_code) ]
89
- pub fn generate ( ) { }
90
-
91
16
// Use a build-time generated set of type ids to match a type with a conversion fn
92
- #[ cfg( all ( srcbuild, not ( const_type_id ) ) ) ]
17
+ #[ cfg( srcbuild) ]
93
18
pub ( super ) fn from_any < ' v > (
94
19
value : & ' v ( dyn std:: any:: Any + ' static ) ,
95
20
) -> Option < crate :: kv:: value:: internal:: Primitive < ' v > > {
@@ -107,7 +32,7 @@ pub(super) fn from_any<'v>(
107
32
}
108
33
109
34
// When the `src_build` config is not set then we're in the build script
110
- #[ cfg( all ( not( srcbuild) , not ( const_type_id ) ) ) ]
35
+ #[ cfg( not( srcbuild) ) ]
111
36
#[ allow( dead_code) ]
112
37
pub fn generate ( ) {
113
38
use std:: path:: Path ;
0 commit comments