pub trait ConstPowerOfTwo:
Sized
+ ConstZero
+ ConstOne {
// Required methods
fn is_power_of_two(&self) -> bool;
fn next_power_of_two(self) -> Self;
fn checked_next_power_of_two(self) -> Option<Self>;
}Expand description
Const-compatible power-of-two operations.
These methods mirror the inherent methods on primitive integers but are not part of num_traits.
§Unsigned types only
This trait is designed for unsigned integer types. Implementing it for
signed types may produce unexpected results (e.g., negative values are
never powers of two, and next_power_of_two behavior is undefined for
negative inputs).
Required Methods§
Sourcefn is_power_of_two(&self) -> bool
fn is_power_of_two(&self) -> bool
Returns true if self is a power of two.
Zero is not a power of two.
Sourcefn next_power_of_two(self) -> Self
fn next_power_of_two(self) -> Self
Returns the smallest power of two greater than or equal to self.
§Panics
Panics if the result overflows (i.e., self > (1 << (bits-1))).
Sourcefn checked_next_power_of_two(self) -> Option<Self>
fn checked_next_power_of_two(self) -> Option<Self>
Returns the smallest power of two greater than or equal to self.
Returns None if the result would overflow.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.