#[non_exhaustive]pub enum Error {
#[non_exhaustive] InvalidChar {
index: usize,
byte: u8,
},
#[non_exhaustive] OutputTooSmall {
required: usize,
},
#[non_exhaustive] LengthMismatch {
expected: usize,
actual: usize,
},
OddLength,
Overflow,
}Expand description
An error from checked hexadecimal encoding or decoding.
Slice conversions leave the entire destination unchanged on error. Each
operation documents its validation order: for example, crate::hex_decode
checks odd input length, destination capacity, then characters. A character
check such as crate::hex_check returns a boolean instead of this type.
This enum and its data-bearing variants are non-exhaustive. Match fields
using .. and keep a wildcard arm for future variants. Downstream crates
cannot construct the non-exhaustive data-bearing variants directly.
Display and Debug provide
diagnostics; their output is not a stable serialization format. Match variants
and fields when handling errors programmatically.
core::error::Error is implemented with every feature set.
§Examples
use faster_hex::{hex_decode, Error};
let mut destination = [0; 1];
let error = hex_decode(b"0011", &mut destination).unwrap_err();
let required = match error {
Error::OutputTooSmall { required, .. } => Some(required),
_ => None,
};
assert_eq!(required, Some(2));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
#[non_exhaustive]InvalidChar
The input contains a non-hex byte or a letter in a disallowed case.
Identifies the first invalid byte in source order, including for SIMD conversions. Non-ASCII and non-UTF-8 input is represented without loss.
Fields
This variant is marked as non-exhaustive
#[non_exhaustive]OutputTooSmall
The destination cannot hold the complete output.
Used by slice conversion and fixed-capacity string encoding. Extra capacity is allowed; this error only indicates insufficient capacity.
Fields
This variant is marked as non-exhaustive
#[non_exhaustive]LengthMismatch
An array decoder’s input has the wrong decoded length.
Both shorter and longer inputs fail. This is distinct from
OutputTooSmall, which allows spare capacity.
Fields
This variant is marked as non-exhaustive
OddLength
The hex input contains an odd number of bytes and cannot form byte pairs.
Decoders check this before capacity, exact length or character validity. Character-only checkers may still accept an odd-length input.
Overflow
The encoded length cannot be represented as a usize.
This is a length-arithmetic error, not an allocation-failure result.
Trait Implementations§
impl Copy for Error
impl Eq for Error
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()