Skip to main content

IsPowerOfTwo

Trait IsPowerOfTwo 

Source
pub trait IsPowerOfTwo: Sized {
    // Required method
    fn is_power_of_two(self) -> bool;
}
Expand description

Power-of-two predicate, for unsigned integers.

Required Methods§

Source

fn is_power_of_two(self) -> bool

Returns true if and only if self == 2^k for some integer k. Zero is not a power of two.

use const_num_traits::IsPowerOfTwo;

assert!(IsPowerOfTwo::is_power_of_two(16u8));
assert!(!IsPowerOfTwo::is_power_of_two(10u8));
assert!(!IsPowerOfTwo::is_power_of_two(0u8));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl IsPowerOfTwo for u8

Source§

impl IsPowerOfTwo for u16

Source§

impl IsPowerOfTwo for u32

Source§

impl IsPowerOfTwo for u64

Source§

impl IsPowerOfTwo for u128

Source§

impl IsPowerOfTwo for usize

Implementors§