#[non_exhaustive]pub enum CanonError {
Show 13 variants
Truncated {
offset: usize,
needed: usize,
},
TrailingData {
count: usize,
},
NonShortestInteger {
offset: usize,
value: u64,
used: usize,
},
IndefiniteLength {
offset: usize,
},
Float {
offset: usize,
},
NonTextKey {
offset: usize,
},
DuplicateKey {
offset: usize,
key: String,
},
UnsortedKeys {
offset: usize,
previous: String,
current: String,
},
InvalidUtf8 {
offset: usize,
},
NotNfc {
offset: usize,
text: String,
},
Unsupported {
offset: usize,
detail: &'static str,
},
TooDeep {
offset: usize,
limit: usize,
},
TooLarge {
size: usize,
limit: usize,
},
}Expand description
A way in which bytes failed the canonical serialization profile.
Section 4.1 requires an implementation to reject non-canonical bytes rather than repair them, so every variant here is a hard failure. The variants are distinct because the command-line tools name the violated rule on stderr, and the conformance scenarios assert on that name.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Truncated
Input ended in the middle of an item.
Fields
TrailingData
Bytes remained after a complete top-level item.
NonShortestInteger
An item’s argument – an integer, a length, or a simple value such as
null – used a longer encoding than necessary.
Fields
IndefiniteLength
An indefinite-length string, array, or map was present.
Float
A floating point value was present.
NonTextKey
A map key was not a text string.
DuplicateKey
Two map keys were equal.
UnsortedKeys
Map keys were not in ascending UTF-8 byte order.
Fields
InvalidUtf8
A text string was not valid UTF-8.
NotNfc
A text string was not in Unicode Normalization Form C.
Unsupported
A major type or simple value outside the profile was present.
TooDeep
Nesting exceeded the implementation limit.
TooLarge
The item was larger than Section 4.5 permits.
Implementations§
Source§impl CanonError
impl CanonError
Sourcepub fn rule(&self) -> &'static str
pub fn rule(&self) -> &'static str
The short rule name this violation maps to.
Stable across releases: the conformance scenarios match on it.
§Example
use publet_core::cbor::decode;
let error = decode(&[0xa2, 0x61, b'b', 0x01, 0x61, b'a', 0x02]).unwrap_err(); // {"b": 1, "a": 2}
assert_eq!(error.rule(), "sorted map keys");Trait Implementations§
Source§impl Clone for CanonError
impl Clone for CanonError
Source§impl Debug for CanonError
impl Debug for CanonError
Source§impl Display for CanonError
impl Display for CanonError
impl Eq for CanonError
Source§impl Error for CanonError
impl Error for CanonError
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()