@@ -483,6 +483,24 @@ macro_rules! impl_to_value_primitive {
483
483
} ;
484
484
}
485
485
486
+ macro_rules! impl_to_value_nonzero_primitive {
487
+ ( $( $into_ty: ident, ) * ) => {
488
+ $(
489
+ impl ToValue for std:: num:: $into_ty {
490
+ fn to_value( & self ) -> Value {
491
+ Value :: from( self . get( ) )
492
+ }
493
+ }
494
+
495
+ impl <' v> From <std:: num:: $into_ty> for Value <' v> {
496
+ fn from( value: std:: num:: $into_ty) -> Self {
497
+ Value :: from( value. get( ) )
498
+ }
499
+ }
500
+ ) *
501
+ } ;
502
+ }
503
+
486
504
macro_rules! impl_value_to_primitive {
487
505
( $( #[ doc = $doc: tt] $into_name: ident -> $into_ty: ty, ) * ) => {
488
506
impl <' v> Value <' v> {
@@ -500,6 +518,12 @@ impl_to_value_primitive![
500
518
usize , u8 , u16 , u32 , u64 , u128 , isize , i8 , i16 , i32 , i64 , i128 , f32 , f64 , char , bool ,
501
519
] ;
502
520
521
+ #[ rustfmt:: skip]
522
+ impl_to_value_nonzero_primitive ! [
523
+ NonZeroUsize , NonZeroU8 , NonZeroU16 , NonZeroU32 , NonZeroU64 , NonZeroU128 ,
524
+ NonZeroIsize , NonZeroI8 , NonZeroI16 , NonZeroI32 , NonZeroI64 , NonZeroI128 ,
525
+ ] ;
526
+
503
527
impl_value_to_primitive ! [
504
528
#[ doc = "Try convert this value into a `u64`." ]
505
529
to_u64 -> u64 ,
@@ -720,6 +744,11 @@ pub(crate) mod tests {
720
744
Value :: from( 32u32 ) ,
721
745
Value :: from( 64u64 ) ,
722
746
Value :: from( 1usize ) ,
747
+ Value :: from( std:: num:: NonZeroU8 :: new( 8 ) . unwrap( ) ) ,
748
+ Value :: from( std:: num:: NonZeroU16 :: new( 16 ) . unwrap( ) ) ,
749
+ Value :: from( std:: num:: NonZeroU32 :: new( 32 ) . unwrap( ) ) ,
750
+ Value :: from( std:: num:: NonZeroU64 :: new( 64 ) . unwrap( ) ) ,
751
+ Value :: from( std:: num:: NonZeroUsize :: new( 1 ) . unwrap( ) ) ,
723
752
]
724
753
. into_iter ( )
725
754
}
@@ -731,6 +760,11 @@ pub(crate) mod tests {
731
760
Value :: from( -32i32 ) ,
732
761
Value :: from( -64i64 ) ,
733
762
Value :: from( -1isize ) ,
763
+ Value :: from( std:: num:: NonZeroI8 :: new( -8 ) . unwrap( ) ) ,
764
+ Value :: from( std:: num:: NonZeroI16 :: new( -16 ) . unwrap( ) ) ,
765
+ Value :: from( std:: num:: NonZeroI32 :: new( -32 ) . unwrap( ) ) ,
766
+ Value :: from( std:: num:: NonZeroI64 :: new( -64 ) . unwrap( ) ) ,
767
+ Value :: from( std:: num:: NonZeroIsize :: new( -1 ) . unwrap( ) ) ,
734
768
]
735
769
. into_iter ( )
736
770
}
0 commit comments