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>
impl<const BITS: u32, S: SignedInteger> CheckedSignedFixed<BITS, S>
Sourcepub fn new_fixed(value: S) -> Result<Self, CheckedError>
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);