1
1
//! Implementations of [StaticReflect] for core types (for `#![no_std]`)
2
- use crate :: StaticReflect ;
3
- use crate :: types:: { TypeInfo , SimpleNonZeroRepr } ;
2
+ use crate :: { StaticReflect , PrimInt , PrimFloat } ;
3
+ use crate :: types:: { TypeInfo , IntSize , IntType , SimpleNonZeroRepr , FloatSize } ;
4
4
use std:: mem:: { self , ManuallyDrop } ;
5
5
use core:: ptr:: NonNull ;
6
6
use std:: num:: { NonZeroI32 , NonZeroU32 , NonZeroU8 , NonZeroUsize } ;
@@ -15,13 +15,15 @@ macro_rules! impl_primitive {
15
15
macro_rules! impl_ints {
16
16
( $( $target: ty) ,* ) => {
17
17
$( unsafe impl StaticReflect for $target {
18
+ const TYPE_INFO : TypeInfo <' static > = TypeInfo :: Integer ( Self :: INT_TYPE ) ;
19
+ }
20
+ unsafe impl PrimInt for $target {
21
+ const INT_SIZE : IntSize = IntSize :: unwrap_from_bytes( std:: mem:: size_of:: <Self >( ) ) ;
18
22
#[ allow( unused_comparisons) ]
19
- const TYPE_INFO : TypeInfo <' static > = {
20
- let size = std:: mem:: size_of:: <$target>( ) ;
21
- let signed = <$target>:: MIN < 0 ;
22
- TypeInfo :: integer( size, signed)
23
- } ;
24
- } ) *
23
+ const SIGNED : bool = <$target>:: MIN < 0 ;
24
+ const INT_TYPE : IntType = IntType { size: Self :: INT_SIZE , signed: Self :: SIGNED } ;
25
+ }
26
+ impl crate :: sealed:: Sealed for $target { } ) *
25
27
}
26
28
}
27
29
// NOTE: Pointer sized integers have machine-dependent implementation :(
@@ -33,6 +35,14 @@ impl_primitive!(() => TypeInfo::Unit);
33
35
impl_primitive ! ( bool => TypeInfo :: Bool ) ;
34
36
impl_primitive ! ( f32 => TypeInfo :: F32 ) ;
35
37
impl_primitive ! ( f64 => TypeInfo :: F64 ) ;
38
+ impl crate :: sealed:: Sealed for f32 { }
39
+ unsafe impl PrimFloat for f32 {
40
+ const FLOAT_SIZE : FloatSize = FloatSize :: Single ;
41
+ }
42
+ impl crate :: sealed:: Sealed for f64 { }
43
+ unsafe impl PrimFloat for f64 {
44
+ const FLOAT_SIZE : FloatSize = FloatSize :: Double ;
45
+ }
36
46
37
47
// Builtin support for the never type
38
48
impl_primitive ! ( ! => TypeInfo :: Never ) ;
0 commit comments