Enum binrw::error::Error

source ·
#[non_exhaustive]
pub enum Error { BadMagic { pos: u64, found: Box<dyn Debug + Send + Sync>, }, AssertFail { pos: u64, message: String, }, Io(Error), Custom { pos: u64, err: Box<dyn CustomError>, }, NoVariantMatch { pos: u64, }, EnumErrors { pos: u64, variant_errors: Vec<(&'static str, Error)>, }, Backtrace(Backtrace), }
Expand description

The error type used by BinRead.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

BadMagic

Fields

§pos: u64

The byte position of the unexpected magic in the reader.

§found: Box<dyn Debug + Send + Sync>

The value which was actually read.

An expected magic number was not found.

§

AssertFail

Fields

§pos: u64

The byte position of the start of the field or object that raised an error.

§message: String

The failure message.

An assertion failed.

This variant is used for assert directives which use a string literal instead of an error object. Assertions that use error objects are represented by the Custom variant.

§

Io(Error)

An error occurred in the underlying reader while reading or seeking to data.

§

Custom

Fields

§pos: u64

The byte position of the start of the field or object that raised an error.

§err: Box<dyn CustomError>

The original error.

A user-generated error.

This variant is used for assert directives which use an error object instead of a string literal. Assertions that use string literals are represented by the AssertFail variant.

§

NoVariantMatch

Fields

§pos: u64

The byte position of the unparsable data in the reader.

None of the variants of an enum could successfully be parsed from the data in the reader.

This variant is used when the return_unexpected_error directive is set on an enum.

§

EnumErrors

Fields

§pos: u64

The byte position of the unparsable data in the reader.

§variant_errors: Vec<(&'static str, Error)>

The original errors which occurred when trying to parse each variant.

The first field of the tuple is the name of the variant, and the second field is the error that occurred when parsing that variant.

None of the variants of an enum could successfully be parsed from the data in the reader.

This variant is used when the return_all_errors directive is set on an enum (which is the default).

§

Backtrace(Backtrace)

An error with additional frames of context used to construct a backtrace

Implementations§

source§

impl Error

source

pub fn root_cause(&self) -> &Self

Returns the source error. For a Backtrace this is the error that caused it, for every other error this returns self

source

pub fn is_eof(&self) -> bool

Check if the root cause of this error is an Error::Io and an io::ErrorKind::UnexpectedEof.

source

pub fn custom_err<T: CustomError + 'static>(&self) -> Option<&T>

Returns a reference to the boxed error object if this Error is a custom error of type T, or None if it isn’t.

Trait Implementations§

source§

impl ContextExt for Error

source§

fn with_context<Frame: Into<BacktraceFrame>>(self, frame: Frame) -> Self

Adds a new context frame to the error, consuming the original error.
source§

fn with_message(self, message: impl Into<Cow<'static, str>>) -> Self

Adds a new frame of context to the error with the given message, consuming the original error. Read more
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, f: &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)>

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
source§

impl From<Error> for Error

source§

fn from(err: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CustomError for Twhere T: Display + Debug + Send + Sync + 'static,

source§

fn as_any(&self) -> &(dyn Any + Send + Sync + 'static)

source§

fn as_any_mut(&mut self) -> &mut (dyn Any + Send + Sync + 'static)

source§

fn as_box_any(self: Box<T, Global>) -> Box<dyn Any + Send + Sync, Global>

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

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

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

§

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 Twhere U: TryFrom<T>,

§

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.