#[non_exhaustive]pub struct DecodeError {
pub offset: usize,
pub kind: DecodingKind,
pub context: &'static str,
pub label: &'static str,
pub values: [u64; 2],
pub index: Option<u16>,
}Expand description
A decoder’s refusal, without an allocated message (#1646).
It displays as decoding error at offset {offset}: {context}: {label},
leaving out {context}: when the context is empty, and with each {}
in the label replaced by the next of values in decimal,
each {:#x} in hexadecimal, or each {:#04X} as an upper-case,
zero-padded octet such as 0x0B. An index follows the
context as [{index}].
use bacnet_types::error::{DecodeError, DecodingKind, Error};
let refused = DecodeError::new(DecodingKind::Trailing, 9, "{} trailing byte(s)")
.within("IAm")
.with_value(2);
assert_eq!(refused.to_string(), "decoding error at offset 9: IAm: 2 trailing byte(s)");
assert_eq!(Error::from(refused).reject_reason(), Some(DecodingKind::Trailing.reject_reason()));It is #[non_exhaustive]: build one with new and the
builder methods.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.offset: usizeByte offset where the decoder found the fault.
kind: DecodingKindWhich kind of fault it is.
context: &'static strThe production or member being decoded, such as "WhoIs low limit";
empty when the decoder names none.
label: &'static strWhat is wrong, such as "expected context tag [{}]".
values: [u64; 2]The numbers the label’s placeholders stand for, in order; a slot with no placeholder is 0.
index: Option<u16>The zero-based position of the list item the fault is in, such as a file record, when the decoder names one (#1776). It sits in the struct’s padding, so the error is no larger for it.
Implementations§
Source§impl DecodeError
impl DecodeError
Sourcepub const fn new(kind: DecodingKind, offset: usize, label: &'static str) -> Self
pub const fn new(kind: DecodingKind, offset: usize, label: &'static str) -> Self
A fault of kind at offset, described by label.
Sourcepub const fn with_value(self, value: u64) -> Self
pub const fn with_value(self, value: u64) -> Self
The same fault, with the number the label’s one placeholder stands for.
Sourcepub const fn with_values(self, first: u64, second: u64) -> Self
pub const fn with_values(self, first: u64, second: u64) -> Self
The same fault, with the numbers the label’s two placeholders stand for.
Trait Implementations§
Source§impl Clone for DecodeError
impl Clone for DecodeError
impl Copy for DecodeError
Source§impl Debug for DecodeError
impl Debug for DecodeError
Source§impl Display for DecodeError
impl Display for DecodeError
impl Eq for DecodeError
Source§impl Error for DecodeError
impl Error for DecodeError
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()