#[non_exhaustive]pub struct EncodeError {
pub context: &'static str,
pub label: &'static str,
pub values: [u32; 2],
pub decode_offset: Option<u32>,
}Expand description
A value an encoder or validator refused to put on the wire, without an allocated message (#1802).
It displays as encoding error: {context}: {label}, leaving out
{context}: when the context is empty and with the label’s placeholders
filled from values. One that restates a decoder’s
refusal of octets the encoder was handed, such as a captured raw value
(see from_decode), adds that refusal’s offset:
encoding error: decoding error at offset {offset}: {context}: {label}.
use bacnet_types::error::{EncodeError, Error};
let refused = EncodeError::new("mac-address of {} octets exceeds the {}-octet limit")
.within("BACnetAddress")
.with_values(19, 18);
assert_eq!(
Error::from(refused).to_string(),
"encoding error: BACnetAddress: mac-address of 19 octets exceeds the 18-octet limit"
);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.context: &'static strThe production or member being encoded, such as "BACnetNameValue";
empty when the encoder names none.
label: &'static strWhat is wrong, such as "exceeds {} property values".
values: [u32; 2]The numbers the label’s placeholders stand for, in order; a slot with
no placeholder is 0. They are 32 bits wide, so the error fits in
Error without widening it: a number restated from a
decoder’s refusal past u32::MAX reads as u32::MAX.
decode_offset: Option<u32>The offset, within the octets the encoder was handed, of the fault a
decoder found there; None when the refusal is the encoder’s own. An
offset past u32::MAX reads as u32::MAX.
Implementations§
Source§impl EncodeError
impl EncodeError
Sourcepub fn from_decode(refused: &DecodeError) -> Self
pub fn from_decode(refused: &DecodeError) -> Self
The refusal of octets an encoder was handed, which refused found
malformed: its context, label, numbers and offset. A list item index
the decoder named is not kept.
Sourcepub const fn within(self, context: &'static str) -> Self
pub const fn within(self, context: &'static str) -> Self
The same refusal, met encoding context.
Sourcepub const fn with_value(self, value: u32) -> Self
pub const fn with_value(self, value: u32) -> Self
The same refusal, with the number the label’s one placeholder stands for.
Sourcepub const fn with_values(self, first: u32, second: u32) -> Self
pub const fn with_values(self, first: u32, second: u32) -> Self
The same refusal, with the numbers the label’s two placeholders stand for.
Trait Implementations§
Source§impl Clone for EncodeError
impl Clone for EncodeError
impl Copy for EncodeError
Source§impl Debug for EncodeError
impl Debug for EncodeError
Source§impl Display for EncodeError
impl Display for EncodeError
impl Eq for EncodeError
Source§impl Error for EncodeError
impl Error for EncodeError
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()