Skip to content

Commit 0156ef1

Browse files
committed
Max working.
1 parent e846f9c commit 0156ef1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

library/core/src/num/nonzero.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,3 +895,23 @@ macro_rules! nonzero_unsigned_is_power_of_two {
895895
}
896896

897897
nonzero_unsigned_is_power_of_two! { NonZeroU8 NonZeroU16 NonZeroU32 NonZeroU64 NonZeroU128 NonZeroUsize }
898+
899+
macro_rules! nonzero_max {
900+
( $( $Ty: ident($Int: ty) )+ ) => {
901+
$(
902+
903+
impl $Ty {
904+
#[unstable(feature = "nonzero_max", issue = "89065")]
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);")]
907+
//SAFETY: Since the MAX value, for any supported integer type, is greater than 0,
908+
// the MAX will always be non-zero.
909+
pub const MAX : $Ty = unsafe { $Ty::new_unchecked(<$Int>::MAX) };
910+
}
911+
)+
912+
}
913+
}
914+
915+
nonzero_max! { NonZeroU8(u8) NonZeroI8(i8) NonZeroU16(u16) NonZeroI16(i16) NonZeroU32(u32) NonZeroI32(i32)
916+
NonZeroU64(u64) NonZeroI64(i64) NonZeroUsize(usize) NonZeroIsize(isize)
917+
}

0 commit comments

Comments
 (0)