Trait BitsExt

Source
pub trait BitsExt {
    // Required methods
    fn extract_bit(self, index: usize) -> bool;
    fn extract_bits(self, range: Range<usize>) -> Self;
    fn replace_bit(self, index: usize, value: bool) -> Self;
    fn replace_bits(self, range: Range<usize>, value: Self) -> Self;
}
Expand description

Provides a simpler interface to extract from a given value and replace bits in a given value than manipulating the value directly using bit shifting and masking.

Required Methods§

Source

fn extract_bit(self, index: usize) -> bool

Extracts a single bit from the integer at the given index. Returns true if the bit is set, false otherwise.

Source

fn extract_bits(self, range: Range<usize>) -> Self

Extracts the given range of bits from the integer.

Source

fn replace_bit(self, index: usize, value: bool) -> Self

Replaces a single bit in the integer at the given index.

Source

fn replace_bits(self, range: Range<usize>, value: Self) -> Self

Replaces the given range of bits in the integer with the given value.

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.

Implementations on Foreign Types§

Source§

impl BitsExt for i8

Source§

fn extract_bit(self, index: usize) -> bool

Source§

fn extract_bits(self, range: Range<usize>) -> Self

Source§

fn replace_bit(self, index: usize, value: bool) -> Self

Source§

fn replace_bits(self, range: Range<usize>, value: Self) -> Self

Source§

impl BitsExt for i16

Source§

fn extract_bit(self, index: usize) -> bool

Source§

fn extract_bits(self, range: Range<usize>) -> Self

Source§

fn replace_bit(self, index: usize, value: bool) -> Self

Source§

fn replace_bits(self, range: Range<usize>, value: Self) -> Self

Source§

impl BitsExt for i32

Source§

fn extract_bit(self, index: usize) -> bool

Source§

fn extract_bits(self, range: Range<usize>) -> Self

Source§

fn replace_bit(self, index: usize, value: bool) -> Self

Source§

fn replace_bits(self, range: Range<usize>, value: Self) -> Self

Source§

impl BitsExt for i64

Source§

fn extract_bit(self, index: usize) -> bool

Source§

fn extract_bits(self, range: Range<usize>) -> Self

Source§

fn replace_bit(self, index: usize, value: bool) -> Self

Source§

fn replace_bits(self, range: Range<usize>, value: Self) -> Self

Source§

impl BitsExt for isize

Source§

fn extract_bit(self, index: usize) -> bool

Source§

fn extract_bits(self, range: Range<usize>) -> Self

Source§

fn replace_bit(self, index: usize, value: bool) -> Self

Source§

fn replace_bits(self, range: Range<usize>, value: Self) -> Self

Source§

impl BitsExt for u8

Source§

fn extract_bit(self, index: usize) -> bool

Source§

fn extract_bits(self, range: Range<usize>) -> Self

Source§

fn replace_bit(self, index: usize, value: bool) -> Self

Source§

fn replace_bits(self, range: Range<usize>, value: Self) -> Self

Source§

impl BitsExt for u16

Source§

fn extract_bit(self, index: usize) -> bool

Source§

fn extract_bits(self, range: Range<usize>) -> Self

Source§

fn replace_bit(self, index: usize, value: bool) -> Self

Source§

fn replace_bits(self, range: Range<usize>, value: Self) -> Self

Source§

impl BitsExt for u32

Source§

fn extract_bit(self, index: usize) -> bool

Source§

fn extract_bits(self, range: Range<usize>) -> Self

Source§

fn replace_bit(self, index: usize, value: bool) -> Self

Source§

fn replace_bits(self, range: Range<usize>, value: Self) -> Self

Source§

impl BitsExt for u64

Source§

fn extract_bit(self, index: usize) -> bool

Source§

fn extract_bits(self, range: Range<usize>) -> Self

Source§

fn replace_bit(self, index: usize, value: bool) -> Self

Source§

fn replace_bits(self, range: Range<usize>, value: Self) -> Self

Source§

impl BitsExt for usize

Source§

fn extract_bit(self, index: usize) -> bool

Source§

fn extract_bits(self, range: Range<usize>) -> Self

Source§

fn replace_bit(self, index: usize, value: bool) -> Self

Source§

fn replace_bits(self, range: Range<usize>, value: Self) -> Self

Implementors§