Struct FixedSignedBitCount

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

Source§

fn clone(&self) -> FixedSignedBitCount<BITS>

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 BITS: u32> Debug for FixedSignedBitCount<BITS>

Source§

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

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

impl<const BITS: u32> From<FixedSignedBitCount<BITS>> for SignedBitCount<BITS>

Source§

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>

Source§

type Error = SignedBitCount<MAX>

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

fn try_from(count: SignedBitCount<MAX>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

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> 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<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.