Skip to main content

BitWidth

Trait BitWidth 

Source
pub trait BitWidth: Sized {
    // Required method
    fn bit_width(self) -> u32;
}
Expand description

Computes the minimal number of bits required to represent an unsigned value.

Required Methods§

Source

fn bit_width(self) -> u32

Returns the minimum number of bits required to represent self, i.e. BITS - leading_zeros. Returns 0 for 0. Like std, this is only provided for unsigned types.

use const_num_traits::BitWidth;

assert_eq!(BitWidth::bit_width(0u8), 0);
assert_eq!(BitWidth::bit_width(0b0101_0000u8), 7);

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 BitWidth for u8

Source§

impl BitWidth for u16

Source§

impl BitWidth for u32

Source§

impl BitWidth for u64

Source§

impl BitWidth for u128

Source§

impl BitWidth for usize

Implementors§