11//! Implementations of [StaticReflect] for core types (for `#![no_std]`)
22use crate :: StaticReflect ;
3- use crate :: types:: { TypeInfo , SimpleNonZeroPointer } ;
3+ use crate :: types:: { TypeInfo , SimpleNonZeroRepr } ;
44use std:: mem:: { self , ManuallyDrop } ;
55use core:: ptr:: NonNull ;
6+ use std:: num:: { NonZeroI32 , NonZeroU32 , NonZeroU8 , NonZeroUsize } ;
67
78macro_rules! impl_primitive {
89 ( $target: ty => $info: expr) => {
@@ -64,11 +65,30 @@ unsafe impl <T> StaticReflect for *const T {
6465 const TYPE_INFO : TypeInfo < ' static > = TypeInfo :: Pointer ;
6566}
6667
67- unsafe impl < T > SimpleNonZeroPointer for NonNull < T > { }
68+ unsafe impl < T > SimpleNonZeroRepr for NonNull < T > { }
6869unsafe impl < T > StaticReflect for NonNull < T > {
6970 const TYPE_INFO : TypeInfo < ' static > = TypeInfo :: Pointer ;
7071}
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+ }
7188
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