pub struct FixedBitCount<const BITS: u32>;
Expand description
A fixed number of bits to be consumed or written
Analagous to BitCount
, this is a zero-sized type
whose value is fixed at compile-time and cannot be changed.
§Example
use bitstream_io::{
BigEndian, BitRead, BitReader, BitWrite, BitWriter, CheckedUnsignedFixed, FixedBitCount,
};
type FourBits = CheckedUnsignedFixed<4, u8>;
let input: &[u8] = &[0b0001_1111, 0b0110_1001];
let mut r = BitReader::endian(input, BigEndian);
// read 4, 4-bit values
let v1 = r.read_checked::<FourBits>(FixedBitCount).unwrap();
let v2 = r.read_checked::<FourBits>(FixedBitCount).unwrap();
let v3 = r.read_checked::<FourBits>(FixedBitCount).unwrap();
let v4 = r.read_checked::<FourBits>(FixedBitCount).unwrap();
assert_eq!(v1.into_value(), 0b0001);
assert_eq!(v2.into_value(), 0b1111);
assert_eq!(v3.into_value(), 0b0110);
assert_eq!(v4.into_value(), 0b1001);
// write those same values back to disk
let mut w = BitWriter::endian(vec![], BigEndian);
w.write_checked(v1).unwrap();
w.write_checked(v2).unwrap();
w.write_checked(v3).unwrap();
w.write_checked(v4).unwrap();
// ensure they're the same
assert_eq!(w.into_writer().as_slice(), input);
Trait Implementations§
Source§impl<const BITS: u32> Clone for FixedBitCount<BITS>
impl<const BITS: u32> Clone for FixedBitCount<BITS>
Source§fn clone(&self) -> FixedBitCount<BITS>
fn clone(&self) -> FixedBitCount<BITS>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<const BITS: u32> Debug for FixedBitCount<BITS>
impl<const BITS: u32> Debug for FixedBitCount<BITS>
Source§impl<const BITS: u32> From<FixedBitCount<BITS>> for BitCount<BITS>
impl<const BITS: u32> From<FixedBitCount<BITS>> for BitCount<BITS>
Source§fn from(_count: FixedBitCount<BITS>) -> Self
fn from(_count: FixedBitCount<BITS>) -> Self
Converts to this type from the input type.
impl<const BITS: u32> Copy for FixedBitCount<BITS>
Auto Trait Implementations§
impl<const BITS: u32> Freeze for FixedBitCount<BITS>
impl<const BITS: u32> RefUnwindSafe for FixedBitCount<BITS>
impl<const BITS: u32> Send for FixedBitCount<BITS>
impl<const BITS: u32> Sync for FixedBitCount<BITS>
impl<const BITS: u32> Unpin for FixedBitCount<BITS>
impl<const BITS: u32> UnwindSafe for FixedBitCount<BITS>
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