#[non_exhaustive]pub enum Error {
Show 15 variants
Malformed,
NonDeterministic,
UnexpectedEof,
LengthTooLarge,
NestingTooDeep,
InvalidUtf8,
InvalidHex,
InvalidBase64,
IncompatibleType(DataType),
Overflow,
NegativeUnsigned,
Precision,
InvalidSimpleValue,
InvalidFormat,
InvalidValue,
}Expand description
Errors produced by this crate.
Errors fall into three categories:
Decoding errors are returned when input cannot be parsed as a valid CBOR
value, whether the input is binary, hex, or diagnostic notation. Produced by
Value::decode,
Value::decode_hex,
Value::read_from,
Value::read_hex_from,
Value::from_str (via FromStr),
and the iterators returned by DecodeOptions:
Malformed, NonDeterministic,
UnexpectedEof, LengthTooLarge,
NestingTooDeep,
InvalidUtf8, InvalidHex,
InvalidBase64, InvalidFormat.
Malformed and NonDeterministic
apply to binary and hex input; InvalidFormat is the
catch-all for diagnostic-notation syntax errors and also signals trailing
data after a complete single-item decode.
Accessor errors are returned by the to_*, as_*, and into_*
methods on Value when the value does not match the requested type:
IncompatibleType, Overflow,
NegativeUnsigned, Precision,
InvalidSimpleValue.
Validation errors are returned during construction of typed helpers
like DateTime and EpochTime:
InvalidFormat (reused from the decoding category)
and InvalidValue.
Error is Copy, Eq, Ord, and Hash, so it can be matched,
compared, and used as a map key without allocation. I/O errors are
handled separately by IoError, which wraps either an Error or
a std::io::Error. This separation keeps Error small and
Copy-able while still supporting streaming operations that can
fail with I/O problems.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Malformed
Binary CBOR data is structurally broken.
NonDeterministic
CBOR encoding is valid but not deterministic (non-shortest form, unsorted map keys, etc.).
UnexpectedEof
Input ended before a complete data item was read.
LengthTooLarge
Declared length exceeds addressable memory or reasonable size.
NestingTooDeep
Nesting depth of arrays, maps, or tags exceeds the recursion limit.
InvalidUtf8
Text string contains invalid UTF-8.
InvalidHex
Hex input contains invalid characters.
InvalidBase64
Base64 input contains invalid characters.
IncompatibleType(DataType)
Accessor called on a value of the wrong CBOR type.
Overflow
Integer does not fit in the target type.
NegativeUnsigned
Attempted to read a negative integer as an unsigned type.
Precision
Float conversion would lose precision.
InvalidSimpleValue
Simple value number is in the reserved range 24-31.
InvalidFormat
Textual input did not match the expected syntax. Used for diagnostic-notation parse errors, trailing data after a single-item decode, and invalid date/time strings.
InvalidValue
A value violates semantic constraints.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
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()