[−][src]Struct pushbits::Bits32
32bits container where you can push and pop multiple bits as a integer.
See the crate level documentaion for more details.
Implementations
impl Bits32
[src]
pub const BIT_WIDTH: u32
[src]
Bit width of this container.
pub fn new(bits: u32) -> Self
[src]
Create a new Bits32 container with the given bit pattern.
pub fn get(&self) -> u32
[src]
Copy out the current bit pattern of this container.
Example
let mut bits = Bits32::new(0); bits.push(5, 0b10110_u16); bits.push_bool(true); assert_eq!(0b10110_1, bits.get());
pub fn push<T: Into<u32>>(&mut self, num_bits: u32, value: T)
[src]
Push given number of bits into the LSB of this container using the bit shift left operation.
Panics
It panics if the num_bits
is greater than 31.
Examples
let mut bits = Bits32::new(0); bits.push(8, 0b11100110_u32); bits.push(5, 0b10001_u8); assert_eq!(0b11100110_10001, bits.get());
pub fn push_bool(&mut self, value: bool)
[src]
Push a boolean as a single bit.
Examples
let mut bits = Bits32::new(0); bits.push_bool(true); bits.push_bool(false); assert_eq!(0b10, bits.get());
pub fn pop(&mut self, num_bits: u32) -> u32
[src]
Pop given number of bits out from the MSB of this container using the bit shift left operation.
Panics
It panics if the num_bits
is greater than 31.
Examples
let mut bits = Bits32::new(0xDEADBEEF); assert_eq!(0xDEA, bits.pop(12)); assert_eq!(0xDBE, bits.pop(12)); assert_eq!(0xEF, bits.pop(8));
pub fn pop_bool(&mut self) -> bool
[src]
Pop a single bit out as a boolean.
Examples
let mut bits = Bits32::new(0b101); bits.push(Bits32::BIT_WIDTH - 3, 0_u32); assert_eq!(true, bits.pop_bool()); assert_eq!(false, bits.pop_bool()); assert_eq!(true, bits.pop_bool());
Trait Implementations
impl Clone for Bits32
[src]
impl Default for Bits32
[src]
impl Eq for Bits32
[src]
impl Ord for Bits32
[src]
pub fn cmp(&self, other: &Bits32) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<Bits32> for Bits32
[src]
impl PartialOrd<Bits32> for Bits32
[src]
pub fn partial_cmp(&self, other: &Bits32) -> Option<Ordering>
[src]
pub fn lt(&self, other: &Bits32) -> bool
[src]
pub fn le(&self, other: &Bits32) -> bool
[src]
pub fn gt(&self, other: &Bits32) -> bool
[src]
pub fn ge(&self, other: &Bits32) -> bool
[src]
impl StructuralEq for Bits32
[src]
impl StructuralPartialEq for Bits32
[src]
Auto Trait Implementations
impl RefUnwindSafe for Bits32
[src]
impl Send for Bits32
[src]
impl Sync for Bits32
[src]
impl Unpin for Bits32
[src]
impl UnwindSafe for Bits32
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,