#[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
BadMagic
An expected magic number was not found.
Fields
AssertFail
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.
Fields
Io(Error)
An error occurred in the underlying reader while reading or seeking to data.
Custom
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.
Fields
err: Box<dyn CustomError>
The original error.
NoVariantMatch
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
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).
Fields
Backtrace(Backtrace)
An error with additional frames of context used to construct a backtrace
Implementations§
source§impl Error
impl Error
sourcepub fn root_cause(&self) -> &Self
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
sourcepub fn is_eof(&self) -> bool
pub fn is_eof(&self) -> bool
Check if the root cause of this error is an Error::Io
and an
io::ErrorKind::UnexpectedEof
.
sourcepub fn custom_err<T: CustomError + 'static>(&self) -> Option<&T>
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.