pub struct FixedSignedBitCount<const BITS: u32>;
Expand description
A fixed number of bits to be consumed or written
Analagous to SignedBitCount
, 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,
CheckedSignedFixed, FixedSignedBitCount,
};
type FourBits = CheckedSignedFixed<4, i8>;
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>(FixedSignedBitCount).unwrap();
let v2 = r.read_checked::<FourBits>(FixedSignedBitCount).unwrap();
let v3 = r.read_checked::<FourBits>(FixedSignedBitCount).unwrap();
let v4 = r.read_checked::<FourBits>(FixedSignedBitCount).unwrap();
assert_eq!(v1.into_value(), 1);
assert_eq!(v2.into_value(), -1);
assert_eq!(v3.into_value(), 6);
assert_eq!(v4.into_value(), -7);
// 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 FixedSignedBitCount<BITS>
impl<const BITS: u32> Clone for FixedSignedBitCount<BITS>
Source§fn clone(&self) -> FixedSignedBitCount<BITS>
fn clone(&self) -> FixedSignedBitCount<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 FixedSignedBitCount<BITS>
impl<const BITS: u32> Debug for FixedSignedBitCount<BITS>
Source§impl<const BITS: u32> From<FixedSignedBitCount<BITS>> for SignedBitCount<BITS>
impl<const BITS: u32> From<FixedSignedBitCount<BITS>> for SignedBitCount<BITS>
Source§fn from(_count: FixedSignedBitCount<BITS>) -> Self
fn from(_count: FixedSignedBitCount<BITS>) -> Self
Converts to this type from the input type.
Source§impl<const BITS: u32, const MAX: u32> TryFrom<SignedBitCount<MAX>> for FixedSignedBitCount<BITS>
impl<const BITS: u32, const MAX: u32> TryFrom<SignedBitCount<MAX>> for FixedSignedBitCount<BITS>
Source§type Error = SignedBitCount<MAX>
type Error = SignedBitCount<MAX>
The type returned in the event of a conversion error.
impl<const BITS: u32> Copy for FixedSignedBitCount<BITS>
Auto Trait Implementations§
impl<const BITS: u32> Freeze for FixedSignedBitCount<BITS>
impl<const BITS: u32> RefUnwindSafe for FixedSignedBitCount<BITS>
impl<const BITS: u32> Send for FixedSignedBitCount<BITS>
impl<const BITS: u32> Sync for FixedSignedBitCount<BITS>
impl<const BITS: u32> Unpin for FixedSignedBitCount<BITS>
impl<const BITS: u32> UnwindSafe for FixedSignedBitCount<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