pub trait EndianParse:
Clone
+ Copy
+ Default
+ PartialEq
+ Eq {
// Required methods
fn from_ei_data(ei_data: u8) -> Result<Self, ParseError>;
fn is_little(self) -> bool;
// Provided methods
fn parse_u8_at(
self,
offset: &mut usize,
data: &[u8],
) -> Result<u8, ParseError> { ... }
fn parse_u16_at(
self,
offset: &mut usize,
data: &[u8],
) -> Result<u16, ParseError> { ... }
fn parse_u32_at(
self,
offset: &mut usize,
data: &[u8],
) -> Result<u32, ParseError> { ... }
fn parse_u64_at(
self,
offset: &mut usize,
data: &[u8],
) -> Result<u64, ParseError> { ... }
fn parse_i32_at(
self,
offset: &mut usize,
data: &[u8],
) -> Result<i32, ParseError> { ... }
fn parse_i64_at(
self,
offset: &mut usize,
data: &[u8],
) -> Result<i64, ParseError> { ... }
fn is_big(self) -> bool { ... }
}
Expand description
An all-safe-code endian-aware integer parsing trait.
These methods use safe code to get a subslice from the the byte slice $data at the given $off as a [u8; size_of<$typ>], then calls the corresponding safe endian-aware conversion on it.
These use checked integer math and returns a ParseError on overflow or if $data did not contain enough bytes at $off to perform the conversion.
Required Methods§
Sourcefn from_ei_data(ei_data: u8) -> Result<Self, ParseError>
fn from_ei_data(ei_data: u8) -> Result<Self, ParseError>
Get an endian-aware integer parsing spec for an ELF FileHeader’s
ident[EI_DATA]
byte.
Returns an UnsupportedElfEndianness if this spec doesn’t support parsing the byte-order represented by ei_data. If you’re seeing this error, are you trying to read files of any endianness? i.e. did you want to use AnyEndian?
fn is_little(self) -> bool
Provided Methods§
fn parse_u8_at(self, offset: &mut usize, data: &[u8]) -> Result<u8, ParseError>
fn parse_u16_at( self, offset: &mut usize, data: &[u8], ) -> Result<u16, ParseError>
fn parse_u32_at( self, offset: &mut usize, data: &[u8], ) -> Result<u32, ParseError>
fn parse_u64_at( self, offset: &mut usize, data: &[u8], ) -> Result<u64, ParseError>
fn parse_i32_at( self, offset: &mut usize, data: &[u8], ) -> Result<i32, ParseError>
fn parse_i64_at( self, offset: &mut usize, data: &[u8], ) -> Result<i64, ParseError>
fn is_big(self) -> bool
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.