1
1
//! Implementations of [StaticReflect] for core types (for `#![no_std]`)
2
2
use crate :: StaticReflect ;
3
- use crate :: types:: { TypeInfo , SimpleNonZeroPointer } ;
3
+ use crate :: types:: { TypeInfo , SimpleNonZeroRepr } ;
4
4
use std:: mem:: { self , ManuallyDrop } ;
5
5
use core:: ptr:: NonNull ;
6
+ use std:: num:: { NonZeroI32 , NonZeroU32 , NonZeroU8 , NonZeroUsize } ;
6
7
7
8
macro_rules! impl_primitive {
8
9
( $target: ty => $info: expr) => {
@@ -64,11 +65,30 @@ unsafe impl <T> StaticReflect for *const T {
64
65
const TYPE_INFO : TypeInfo < ' static > = TypeInfo :: Pointer ;
65
66
}
66
67
67
- unsafe impl < T > SimpleNonZeroPointer for NonNull < T > { }
68
+ unsafe impl < T > SimpleNonZeroRepr for NonNull < T > { }
68
69
unsafe impl < T > StaticReflect for NonNull < T > {
69
70
const TYPE_INFO : TypeInfo < ' static > = TypeInfo :: Pointer ;
70
71
}
72
+ unsafe impl SimpleNonZeroRepr for NonZeroUsize { }
73
+ unsafe impl StaticReflect for NonZeroUsize {
74
+ const TYPE_INFO : TypeInfo < ' static > = <usize as StaticReflect >:: TYPE_INFO ;
75
+ }
76
+ unsafe impl SimpleNonZeroRepr for NonZeroU32 { }
77
+ unsafe impl StaticReflect for NonZeroU32 {
78
+ const TYPE_INFO : TypeInfo < ' static > = <u32 as StaticReflect >:: TYPE_INFO ;
79
+ }
80
+ unsafe impl SimpleNonZeroRepr for NonZeroU8 { }
81
+ unsafe impl StaticReflect for NonZeroU8 {
82
+ const TYPE_INFO : TypeInfo < ' static > = <u8 as StaticReflect >:: TYPE_INFO ;
83
+ }
84
+ unsafe impl SimpleNonZeroRepr for NonZeroI32 { }
85
+ unsafe impl StaticReflect for NonZeroI32 {
86
+ const TYPE_INFO : TypeInfo < ' static > = <i32 as StaticReflect >:: TYPE_INFO ;
87
+ }
71
88
72
- unsafe impl < T : SimpleNonZeroPointer > StaticReflect for Option < T > {
73
- const TYPE_INFO : TypeInfo < ' static > = TypeInfo :: Pointer ;
74
- }
89
+
90
+ unsafe impl < T : SimpleNonZeroRepr > StaticReflect for Option < T > {
91
+ /// We have the representation as our internals,
92
+ /// except for the fact we might be null
93
+ const TYPE_INFO : TypeInfo < ' static > = <T as StaticReflect >:: TYPE_INFO ;
94
+ }
0 commit comments