Type Alias CheckedSignedFixed

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

A signed type with a verified value for a fixed number of bits

Aliased Type§

pub struct CheckedSignedFixed<const BITS: u32, T> { /* private fields */ }

Implementations§

Source§

impl<const BITS: u32, S: SignedInteger> CheckedSignedFixed<BITS, S>

Source

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

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

§Examples
use bitstream_io::{SignedBitCount, CheckedSignedFixed, CheckedError};

// a value of 3 fits into a 3 bit count
assert!(CheckedSignedFixed::<3, _>::new_fixed(3i8).is_ok());

// a value of 4 does not fit into a 3 bit count
assert!(matches!(
    CheckedSignedFixed::<3, _>::new_fixed(4i8),
    Err(CheckedError::ExcessiveValue),
));
use bitstream_io::CheckedSignedFixed;

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

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

Trait Implementations§

Source§

impl<const BITS: u32, S: SignedInteger> Checkable for CheckedSignedFixed<BITS, S>

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, S: SignedInteger> CheckablePrimitive for CheckedSignedFixed<BITS, S>

Source§

type CountType = FixedSignedBitCount<BITS>

Our bit count type for reading
Source§

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

Reads our value from the given stream