#[non_exhaustive]pub enum WidthError {
ValueTooLarge {
value: u128,
bits: u32,
},
}Expand description
Errors from checked construction.
Currently the only fallible operation is UInt::try_new (and the TryFrom
impls built on it). Decoding never rejects an out-of-range value: the codec is
dual-use, so unknown values are preserved via a #[catch_all] variant rather than
rejected, and field access masks rather than validates. (Structural decode failures —
EOF, a bad magic, an assert, invalid UTF-8 — are the separate
BitError, not a WidthError.)
§Examples
use bnb::{u4, WidthError};
let err = u4::try_new(20).unwrap_err(); // 20 doesn't fit in 4 bits
assert_eq!(err, WidthError::ValueTooLarge { value: 20, bits: 4 });
assert_eq!(err.to_string(), "value 20 does not fit in 4 bits");Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
ValueTooLarge
A value did not fit in the target integer’s bit width.
Trait Implementations§
Source§impl Clone for WidthError
impl Clone for WidthError
Source§fn clone(&self) -> WidthError
fn clone(&self) -> WidthError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WidthError
impl Debug for WidthError
Source§impl Display for WidthError
impl Display for WidthError
impl Eq for WidthError
Source§impl Error for WidthError
impl Error for WidthError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<WidthError> for BitError
impl From<WidthError> for BitError
Source§fn from(e: WidthError) -> Self
fn from(e: WidthError) -> Self
Bridges a construction error (e.g. UInt::try_new) into a codec error, so it
?-propagates inside a custom parse_with/write_with fn or a converter
that returns BitError. The offset is unknown (0) — the codec’s own
reads/writes carry the real bit offset; this is only for borrowed construction
failures with no cursor context.