@@ -896,22 +896,41 @@ macro_rules! nonzero_unsigned_is_power_of_two {
896
896
897
897
nonzero_unsigned_is_power_of_two ! { NonZeroU8 NonZeroU16 NonZeroU32 NonZeroU64 NonZeroU128 NonZeroUsize }
898
898
899
- macro_rules! nonzero_max {
900
- ( $( $Ty: ident( $Int: ty) ) + ) => {
899
+ macro_rules! nonzero_min_max {
900
+ ( $( $min : expr , $ Ty: ident( $Int: ty) ; ) + ) => {
901
901
$(
902
902
903
903
impl $Ty {
904
904
#[ unstable( feature = "nonzero_max" , issue = "89065" ) ]
905
905
#[ doc = concat!( "The maximum value for a`" , stringify!( $Ty) , "` is the same as `" , stringify!( $Int) , "`" ) ]
906
- #[ doc = concat!( "assert_eq!(" , stringify!( $Ty) , "::MAX, " , stringify!( $Int) , "> ::MAX);" ) ]
906
+ #[ doc = concat!( "assert_eq!(" , stringify!( $Ty) , "::MAX, " , stringify!( $Int) , "::MAX);" ) ]
907
907
//SAFETY: Since the MAX value, for any supported integer type, is greater than 0,
908
908
// the MAX will always be non-zero.
909
909
pub const MAX : $Ty = unsafe { $Ty:: new_unchecked( <$Int>:: MAX ) } ;
910
- }
910
+ #[ unstable( feature = "nonzero_min" , issue = "89065" ) ]
911
+ #[ doc = concat!( "The minimum value for a`" , stringify!( $Ty) , "`." ) ]
912
+ /// # Examples
913
+ ///
914
+ #[ doc = concat!( "assert_eq!(" , stringify!( $Ty) , "::MIN, " , stringify!( $min) , ";" ) ]
915
+ //SAFETY: In the signed case, the minimum integer is negative, and therefore non-zero.
916
+ // In the unsignedd case, we use one, which is non-zero.
917
+ pub const MIN : $Ty = unsafe { $Ty:: new_unchecked( $min) } ;
918
+ }
911
919
) +
912
920
}
913
921
}
914
922
915
- nonzero_max ! { NonZeroU8 ( u8 ) NonZeroI8 ( i8 ) NonZeroU16 ( u16 ) NonZeroI16 ( i16 ) NonZeroU32 ( u32 ) NonZeroI32 ( i32 )
916
- NonZeroU64 ( u64 ) NonZeroI64 ( i64 ) NonZeroUsize ( usize ) NonZeroIsize ( isize )
923
+ nonzero_min_max ! {
924
+ 1 , NonZeroU8 ( u8 ) ;
925
+ 1 , NonZeroU16 ( u16 ) ;
926
+ 1 , NonZeroU32 ( u32 ) ;
927
+ 1 , NonZeroU64 ( u64 ) ;
928
+ 1 , NonZeroU128 ( u128 ) ;
929
+ 1 , NonZeroUsize ( usize ) ;
930
+ i8 :: MIN , NonZeroI8 ( i8 ) ;
931
+ i16 :: MIN , NonZeroI16 ( i16 ) ;
932
+ i32 :: MIN , NonZeroI32 ( i32 ) ;
933
+ i64 :: MIN , NonZeroI64 ( i64 ) ;
934
+ i128 :: MIN , NonZeroI128 ( i128 ) ;
935
+ isize :: MIN , NonZeroIsize ( isize ) ;
917
936
}
0 commit comments