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> { /* private fields */ }
Implementations§
Source§impl<const BITS: u32, U: UnsignedInteger> CheckedUnsignedFixed<BITS, U>
impl<const BITS: u32, U: UnsignedInteger> CheckedUnsignedFixed<BITS, U>
Sourcepub fn new_fixed(value: U) -> Result<Self, CheckedError>
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);