pub struct Reg32Bits<const N: usize>(/* private fields */);Implementations§
Source§impl<const N: usize> Reg32Bits<N>
impl<const N: usize> Reg32Bits<N>
Sourcepub const fn bits(self) -> [u8; N]
pub const fn bits(self) -> [u8; N]
Turn the register bits into a array of 1s and 0s
Can be used in both a const environment and at runtime. This function is especially useful when pattern matching.
use register_bits::prelude::*;
let value: Reg32Bits<4> =
Reg32Bits::new(0b1010).take_low();
match value.bits() {
[1, 0, 1, 0] => {
// Wow, we matched the individual bits
}
_ => unreachable!(),
}Sourcepub fn get(self, index: usize) -> Option<Reg32Bits<1>>
pub fn get(self, index: usize) -> Option<Reg32Bits<1>>
Fetch a bit at runtime
This will fail if index >= N, where N is the size of the Reg32Bits.
use register_bits::prelude::*;
let bits: Reg32Bits<4> =
Reg32Bits::new(0b1100).take_low();
assert_eq!(bits.get(0).unwrap(), 0u8);
assert_eq!(bits.get(1).unwrap(), 0u8);
assert_eq!(bits.get(2).unwrap(), 1u8);
assert_eq!(bits.get(3).unwrap(), 1u8);
assert_eq!(bits.get(4), None);Sourcepub fn zero_count(self) -> usize
pub fn zero_count(self) -> usize
Give the number of ones in the bits
Trait Implementations§
Source§impl<const N: usize> Ord for Reg32Bits<N>
impl<const N: usize> Ord for Reg32Bits<N>
Source§impl<const N: usize> PartialOrd for Reg32Bits<N>
impl<const N: usize> PartialOrd for Reg32Bits<N>
Source§impl<const N: usize> Reg32BitsBitSize for Reg32Bits<N>
impl<const N: usize> Reg32BitsBitSize for Reg32Bits<N>
Source§impl<const F: usize, const T: usize> Reg32BitsUpCast<T> for Reg32Bits<F>where
Reg32Bits<T>: Reg32BitsDownCast<F>,
impl<const F: usize, const T: usize> Reg32BitsUpCast<T> for Reg32Bits<F>where
Reg32Bits<T>: Reg32BitsDownCast<F>,
Source§fn zero_extend(self) -> Reg32Bits<T>
fn zero_extend(self) -> Reg32Bits<T>
Extend the current register bits with 0s on the most significant bits Read more
Source§fn sign_extend(self) -> Reg32Bits<T>
fn sign_extend(self) -> Reg32Bits<T>
Extend the current register bits by copied the most significant bit to the new bits Read more
impl<const N: usize> Copy for Reg32Bits<N>
impl<const N: usize> Eq for Reg32Bits<N>
impl<const N: usize> StructuralPartialEq for Reg32Bits<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for Reg32Bits<N>
impl<const N: usize> RefUnwindSafe for Reg32Bits<N>
impl<const N: usize> Send for Reg32Bits<N>
impl<const N: usize> Sync for Reg32Bits<N>
impl<const N: usize> Unpin for Reg32Bits<N>
impl<const N: usize> UnwindSafe for Reg32Bits<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more