Enum Error

Source
pub enum Error {
    EndOfBuffer,
    ExtraData(usize),
    InvalidVarint(usize),
    InvalidUsize,
    InvalidBool,
    InvalidEnum(u8),
    InvalidLength(usize),
    Invalid(&'static str, &'static str),
    Wrapped(&'static str, Box<dyn Error + Send + Sync>),
}
Expand description

Error type for codec operations

Variants§

§

EndOfBuffer

Indicates that the input buffer (Buf) did not contain enough bytes to read the next piece of data required by a Read implementation. This suggests the input data is truncated or incomplete.

§

ExtraData(usize)

Indicates that after successfully decoding a value using a method like Decode::decode_cfg, there were still unconsumed bytes remaining in the input buffer.

This usually means the input data contained more than just the expected encoded value. The contained usize is the number of bytes that remained unconsumed.

§

InvalidVarint(usize)

A variable-length integer (varint), often used for encoding lengths, could not be decoded correctly. This might happen if:

  • The varint encoding itself is malformed (e.g., too long).
  • The decoded varint value exceeds the capacity of the target integer type.

See the varint module for encoding details.

§

InvalidUsize

Same as InvalidVarint, but specifically for usize-sized varints.

§

InvalidBool

A byte representing a boolean was expected to be 0 (false) or 1 (true), but a different value was encountered during decoding.

§

InvalidEnum(u8)

An enum variant was expected, but the decoded value did not match any of the expected variants.

§

InvalidLength(usize)

A length prefix (e.g., for Vec<T>, Bytes, HashMap<K, V>) was decoded, but its value fell outside the permitted range.

This range is typically configured via a RangeCfg passed within the Cfg parameter to Read::read_cfg. The contained usize is the invalid length that was decoded.

§

Invalid(&'static str, &'static str)

A semantic validation error occurred during decoding, indicating the data, while perhaps structurally valid, does not meet application-specific criteria.

  • The first &'static str provides context (e.g., the name of the type being decoded).
  • The second &'static str provides a specific error message.

Example: Trying to decode a HashMap where keys were not in ascending order.

§

Wrapped(&'static str, Box<dyn Error + Send + Sync>)

An error occurred in underlying code (e.g., external library call, complex validation) and has been wrapped into a codec Error.

  • The &'static str provides context about the operation being performed.
  • The boxed std::error::Error is the original source error.

Allows propagating custom errors through the codec reading process.

Trait Implementations§

Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Auto Trait Implementations§

§

impl Freeze for Error

§

impl !RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl !UnwindSafe for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.