Trait BitRangeExt

Source
pub trait BitRangeExt<T> {
    // Required methods
    fn get_mask(&self) -> T;
    fn is_valid(&self) -> bool;

    // Provided method
    fn check(&self) { ... }
}
Expand description

Trait containing helper methods for BitRange

The methods are needed for:

  • checking if the BitRange is valid for a type T
  • creating masks for a type T

Required Methods§

Source

fn get_mask(&self) -> T

Returns a value of type T that has all the bits in the specified bit range set to 1.

§Example
#[macro_use]
use dbs_arch::cpuid::bit_helper::*;

let range = BitRange {
    msb_index: 7,
    lsb_index: 3,
};
println!("binary value: {:b}", range.get_mask());

The code above will print:

binary value: 11111000
Source

fn is_valid(&self) -> bool

Checks if the current BitRange is valid for type T.

Provided Methods§

Source

fn check(&self)

Asserts if self.is_valid() returns true.

Implementors§