Skip to main content

CheckedUnsignedFixed

Type Alias CheckedUnsignedFixed 

Source
pub type CheckedUnsignedFixed<const BITS: u32, T> = Checked<FixedBitCount<BITS>, T>;
Expand description

An unsigned type with a verified value for a fixed number of bits

Aliased Type§

pub struct CheckedUnsignedFixed<const BITS: u32, T> {
    pub(crate) count: FixedBitCount<BITS>,
    pub(crate) value: T,
}

Fields§

§count: FixedBitCount<BITS>§value: T

Implementations§

Source§

impl<const BITS: u32, U: UnsignedInteger> CheckedUnsignedFixed<BITS, U>

Source

pub fn new_fixed(value: U) -> Result<Self, CheckedError>

Returns our checked value if it fits in the given number of const bits

§Examples
use bitstream_io::{CheckedUnsignedFixed, CheckedError};

// a value of 7 fits into a maximum of 3 bits
assert!(CheckedUnsignedFixed::<3, u8>::new_fixed(0b111).is_ok());

// a value of 8 does not fit into a maximum of 3 bits
assert!(matches!(
    CheckedUnsignedFixed::<3, u8>::new_fixed(0b1000),
    Err(CheckedError::ExcessiveValue),
));
use bitstream_io::CheckedUnsignedFixed;

// a bit count of 9 is too large for u8

// because this is checked at compile-time,
// it does not compile at all
let c = CheckedUnsignedFixed::<9, u8>::new_fixed(1);

Trait Implementations§

Source§

impl<const BITS: u32, U: UnsignedInteger> Checkable for CheckedUnsignedFixed<BITS, U>

Source§

fn write<W: BitWrite + ?Sized>(&self, writer: &mut W) -> Result<()>

Write our value to the given stream
Source§

fn written_bits(&self) -> u32

The number of written bits
Source§

impl<const BITS: u32, U: UnsignedInteger> Checkable for CheckedUnsignedFixed<BITS, U>

Source§

fn write_endian<E, W>( self, writer: &mut W, queue_value: &mut u8, queue_bits: &mut u32, ) -> Result<()>
where E: Endianness, W: Write,

Source§

impl<const BITS: u32, U: UnsignedInteger> CheckablePrimitive for CheckedUnsignedFixed<BITS, U>

Source§

type CountType = FixedBitCount<BITS>

Our bit count type for reading
Source§

fn read<R: BitRead + ?Sized>( reader: &mut R, count: FixedBitCount<BITS>, ) -> Result<Self>

Reads our value from the given stream