Expand description
Read and write numbers in big-endian and little-endian.
§Examples
use eio::ReadExt;
// `Cursor` implements `Read`
let mut rdr = std::io::Cursor::new([
0x37, 0x13,
0x12, 0x34, 0x56, 0x78,
0x00, 0x09, 0x10,
]);
// Read a two byte `u16` in little-endian order
let i: u16 = rdr.read_le()?;
assert_eq!(i, 0x1337);
// Read a four byte `i32` in big-endian order
let i: i32 = rdr.read_be()?;
assert_eq!(i, 0x12345678);
// Read a three byte array
let a: [u8; 3] = rdr.read_array()?;
assert_eq!(a, [0x00, 0x09, 0x10]);
Traits§
- From
Bytes - Conversion of bytes in little/big endian order to a type.
- ReadExt
- Provides extended methods to types that implement
std::io::Read
. - ToBytes
- Conversion of a type to bytes in little/big endian order.
- Write
Ext - Provides extended methods to types that implement
std::io::Write
.