-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Implemented MIN and MAX constants for the non-zero integer types.#89065 #89077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
0156ef1
b5c1fe1
84d88f2
b274022
0f84d19
279f0bf
591b89d
56ce3a2
3cbfdec
7a718e1
87d92f9
2fecb01
5b48c54
5ac53ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -895,3 +895,63 @@ macro_rules! nonzero_unsigned_is_power_of_two { | |
} | ||
|
||
nonzero_unsigned_is_power_of_two! { NonZeroU8 NonZeroU16 NonZeroU32 NonZeroU64 NonZeroU128 NonZeroUsize } | ||
|
||
macro_rules! nonzero_constants_signed { | ||
( $( $Ty: ident($Int: ty); )+ ) => { | ||
$( | ||
impl $Ty { | ||
#[unstable(feature = "nonzero_min_max", issue = "89065")] | ||
#[doc = concat!("The maximum value for a`", stringify!($Ty), "` is the same as `", stringify!($Int), "`")] | ||
/// # Examples | ||
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX, ", stringify!($Int), "::MAX);")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this and the below example need a ``` ... ``` code block, for formatting (though they're not very interesting as doctests). I think including some blank lines as done above for |
||
pub const MAX : $Ty = $Ty::new(<$Int>::MAX).unwrap() ; | ||
mjclements marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[unstable(feature = "nonzero_min_max", issue = "89065")] | ||
#[doc = concat!("The minimum value for a`", stringify!($Ty), "`.")] | ||
/// # Examples | ||
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MIN, ", stringify!($Int), "::MIN;")] | ||
pub const MIN : $Ty = $Ty::new(<$Int>::MIN).unwrap(); | ||
} | ||
)+ | ||
} | ||
} | ||
|
||
nonzero_constants_signed! { | ||
NonZeroI8(i8); | ||
NonZeroI16(i16); | ||
NonZeroI32(i32); | ||
NonZeroI64(i64); | ||
NonZeroI128(i128); | ||
NonZeroIsize(isize); | ||
} | ||
|
||
macro_rules! nonzero_constants_unsigned{ | ||
( $( $Ty: ident($Int: ty); )+ ) => { | ||
$( | ||
impl $Ty { | ||
#[unstable(feature = "nonzero_min_max", issue = "89065")] | ||
#[doc = concat!("The maximum value for a`", stringify!($Ty), "` is the same as `", stringify!($Int), "`")] | ||
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX, ", stringify!($Int), "::MAX);")] | ||
/// Note, while most integer types are defined for every whole number between MIN and | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'd vote for |
||
/// MAX, signed non-zero integers are a special case. They have a 'gap' at 0. | ||
/// # Examples | ||
pub const MAX : $Ty = $Ty::new(<$Int>::MAX).unwrap() ; | ||
#[unstable(feature = "nonzero_min_max", issue = "89065")] | ||
#[doc = concat!("The minimum value for a`", stringify!($Ty), "`.")] | ||
/// Note, while most integer types are defined for every whole number between MIN and | ||
/// MAX, signed non-zero integers are a special case. They have a 'gap' at 0. | ||
/// # Examples | ||
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MIN, ", stringify!($Int), "::MIN;")] | ||
pub const MIN : $Ty = $Ty::new(1).unwrap(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation looks off here. Did the formatter really demand it like that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a macro, it should be formatted manually. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have specific advice on how to format it? I noticed that macros needed manual formatting. Wasn't sure if I had it right though @ibraheemdev . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This closing brace, and the analogous one in |
||
)+ | ||
} | ||
} | ||
|
||
nonzero_constants_unsigned! { | ||
NonZeroU8(u8); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation mismatch here. |
||
NonZeroU16(u16); | ||
NonZeroU32(u32); | ||
NonZeroU64(u64); | ||
NonZeroU128(u128); | ||
NonZeroUsize(usize); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
for a`",
there should be a space betweena
and`
, and the sentence needs a period at the end.