Implement core::error::Error for ParsingError
This commit is contained in:
parent
da1e25f338
commit
bddf58a950
@ -21,3 +21,4 @@ name = "elf"
|
||||
default = ["std", "to_str"]
|
||||
std = []
|
||||
to_str = []
|
||||
nightly = []
|
||||
|
@ -133,6 +133,7 @@
|
||||
//! ```
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![cfg_attr(all(feature = "nightly", not(feature = "std")), feature(error_in_core))]
|
||||
|
||||
pub mod abi;
|
||||
|
||||
|
24
src/parse.rs
24
src/parse.rs
@ -78,12 +78,34 @@ impl std::error::Error for ParseError {
|
||||
ParseError::Utf8Error(ref err) => Some(err),
|
||||
ParseError::TryFromSliceError(ref err) => Some(err),
|
||||
ParseError::TryFromIntError(ref err) => Some(err),
|
||||
#[cfg(feature = "std")]
|
||||
ParseError::IOError(ref err) => Some(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "nightly", not(feature = "std")))]
|
||||
impl core::error::Error for ParseError {
|
||||
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
|
||||
match *self {
|
||||
ParseError::BadMagic(_) => None,
|
||||
ParseError::UnsupportedElfClass(_) => None,
|
||||
ParseError::UnsupportedElfEndianness(_) => None,
|
||||
ParseError::UnsupportedVersion(_) => None,
|
||||
ParseError::BadOffset(_) => None,
|
||||
ParseError::StringTableMissingNul(_) => None,
|
||||
ParseError::BadEntsize(_) => None,
|
||||
ParseError::UnexpectedSectionType(_) => None,
|
||||
ParseError::UnexpectedSegmentType(_) => None,
|
||||
ParseError::UnexpectedAlignment(_) => None,
|
||||
ParseError::SliceReadError(_) => None,
|
||||
ParseError::IntegerOverflow => None,
|
||||
ParseError::Utf8Error(ref err) => Some(err),
|
||||
ParseError::TryFromSliceError(ref err) => Some(err),
|
||||
ParseError::TryFromIntError(ref err) => Some(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Display for ParseError {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
match *self {
|
||||
|
Loading…
x
Reference in New Issue
Block a user