malachite_base/num/arithmetic/
checked_next_power_of_2.rs

1// Copyright © 2025 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8
9use crate::num::arithmetic::traits::CheckedNextPowerOf2;
10
11macro_rules! impl_checked_next_power_of_2 {
12    ($t:ident) => {
13        impl CheckedNextPowerOf2 for $t {
14            type Output = $t;
15
16            /// This is a wrapper over the `checked_next_power_of_two` functions in the standard
17            /// library, for example [this one](u32::checked_next_power_of_two).
18            #[inline]
19            fn checked_next_power_of_2(self) -> Option<$t> {
20                $t::checked_next_power_of_two(self)
21            }
22        }
23    };
24}
25apply_to_unsigneds!(impl_checked_next_power_of_2);