bnum/doc/
checked.rs

1use crate::doc;
2
3macro_rules! impl_desc {
4    () => {
5        doc::arithmetic_impl_desc!(
6            "Checked",
7            "checked",
8            "Each method cannot panic and returns an `Option<Self>`. `None` is returned when overflow would have occurred or there was an attempt to divide by zero or calculate a remainder with a divisor of zero."
9        )
10    };
11}
12
13pub(crate) use impl_desc;
14
15doc::link_doc_comment_method!(
16    checked_abs,
17    checked_add,
18    checked_add_signed,
19    checked_add_unsigned,
20    checked_div,
21    checked_div_euclid,
22    checked_ilog,
23    checked_ilog10,
24    checked_ilog2,
25    checked_mul,
26    checked_neg,
27    checked_next_multiple_of,
28    checked_pow,
29    checked_rem,
30    checked_rem_euclid,
31    checked_shl,
32    checked_shr,
33    checked_sub,
34    checked_sub_unsigned
35);
36
37macro_rules! checked_next_power_of_two {
38    ($sign: ident $bits: literal) => {
39        doc::doc_comment! {
40            #method.checked_next_power_of_two,
41            $sign $bits,
42            "Returns the smallest power of two greater than or equal to `self`. If the next power of two is greater than `Self::MAX`, `None` is returned, otherwise the power of two is wrapped in `Some`.",
43
44            "let n = " doc::type_str!($sign $bits) "::from(2u8);\n"
45            "assert_eq!(n.checked_next_power_of_two(), Some(n));\n"
46            "let m = " doc::type_str!($sign $bits) "::from(3u8);\n"
47            "assert_eq!(" doc::type_str!($sign $bits) "::MAX.checked_next_power_of_two(), None);"
48        }
49    };
50}
51
52pub(crate) use checked_next_power_of_two;