Reg32Bits

Struct Reg32Bits 

Source
pub struct Reg32Bits<const N: usize>(/* private fields */);

Implementations§

Source§

impl Reg32Bits<NUM_BITS>

Source

pub fn new(value: u32) -> Self

Source§

impl<const N: usize> Reg32Bits<N>

Source

pub const ZEROS: Self

A guarenteed N sequential 0’s

Source

pub const ONES: Self

N sequential 1’s

Source

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!(),
}
Source

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);
Source

pub fn one_count(self) -> usize

Give the number of ones in the bits

Source

pub fn zero_count(self) -> usize

Give the number of ones in the bits

Methods from Deref<Target = u32>§

1.43.0 · Source

pub const MIN: u32 = 0u32

1.43.0 · Source

pub const MAX: u32 = 4_294_967_295u32

1.53.0 · Source

pub const BITS: u32 = 32u32

Trait Implementations§

Source§

impl<const N: usize, T: Into<u32>> Add<T> for Reg32Bits<N>

Source§

type Output = Reg32Bits<N>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: T) -> Self::Output

Performs the + operation. Read more
Source§

impl<const N: usize> AsRef<u32> for Reg32Bits<N>

Source§

fn as_ref(&self) -> &u32

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<const N: usize> BitAnd for Reg32Bits<N>

Source§

type Output = Reg32Bits<N>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl<const N: usize> BitOr for Reg32Bits<N>

Source§

type Output = Reg32Bits<N>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl<const N: usize> BitXor for Reg32Bits<N>

Source§

type Output = Reg32Bits<N>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<const N: usize> Clone for Reg32Bits<N>

Source§

fn clone(&self) -> Reg32Bits<N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for Reg32Bits<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Deref for Reg32Bits<N>

Source§

type Target = u32

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<const N: usize, T: Into<u32>> Div<T> for Reg32Bits<N>

Source§

type Output = Reg32Bits<N>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
Source§

impl From<Reg32Bits<1>> for bool

Source§

fn from(item: Reg32Bits<1>) -> bool

Converts to this type from the input type.
Source§

impl<const N: usize> From<Reg32Bits<N>> for u32

Source§

fn from(item: Reg32Bits<N>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> Not for Reg32Bits<N>

Source§

type Output = Reg32Bits<N>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl<const N: usize> Ord for Reg32Bits<N>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq<bool> for Reg32Bits<1>

Source§

fn eq(&self, other: &bool) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<u8> for Reg32Bits<1>

Source§

fn eq(&self, other: &u8) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> PartialEq for Reg32Bits<N>

Source§

fn eq(&self, other: &Reg32Bits<N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> PartialOrd for Reg32Bits<N>

Source§

fn partial_cmp(&self, other: &Reg32Bits<N>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const N: usize> Reg32BitsBitSize for Reg32Bits<N>

Source§

const BIT_SIZE: usize = N

Source§

const BASE_ONES: u32 = Reg32Bits<N>::BASE_ONES

Source§

impl<const F: usize, const T: usize> Reg32BitsUpCast<T> for Reg32Bits<F>

Source§

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>

Extend the current register bits by copied the most significant bit to the new bits Read more
Source§

fn zero_pad(self) -> Reg32Bits<T>

Add extra zeros for the least significant bits Read more
Source§

impl<const N: usize, T: Into<u32>> Rem<T> for Reg32Bits<N>

Source§

type Output = Reg32Bits<N>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: T) -> Self::Output

Performs the % operation. Read more
Source§

impl<const N: usize, T> Shl<T> for Reg32Bits<N>
where u32: Shl<T, Output = u32>,

Source§

type Output = Reg32Bits<N>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: T) -> Self::Output

Performs the << operation. Read more
Source§

impl<const N: usize, T> Shr<T> for Reg32Bits<N>
where u32: Shr<T, Output = u32>,

Source§

type Output = Reg32Bits<N>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: T) -> Self::Output

Performs the >> operation. Read more
Source§

impl<const N: usize, T: Into<u32>> Sub<T> for Reg32Bits<N>

Source§

type Output = Reg32Bits<N>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: T) -> Self::Output

Performs the - operation. Read more
Source§

impl<const N: usize> Copy for Reg32Bits<N>

Source§

impl<const N: usize> Eq for Reg32Bits<N>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.