[−][src]Trait byteio::ReadBytesExt
Extends ReadBytes
with functions for reading numbers.
Examples
Read a u16
from a buffer using native endianness:
use byteio::ReadBytesExt; fn main() { let mut buf: &[u8] = &[0, 1]; #[cfg(target_endian = "little")] let a = buf.read_u16_le(); #[cfg(target_endian = "big")] let a = buf.read_u16_be(); assert!(buf.is_empty()); }
Provided methods
fn read_u8(&mut self) -> u8
fn try_read_u8(&mut self) -> Result<u8>
Attempts to read a u8
from the underlying buffer.
If there are not enough bytes in self
this function will return
Error::EndOfStream
.
fn read_i8(&mut self) -> i8
fn try_read_i8(&mut self) -> Result<i8>
Attempts to read an i8
from the underlying buffer.
If there are not enough bytes in self
this function will return
Error::EndOfStream
.
fn read_u16_le(&mut self) -> u16
Reads a little endian u16
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn read_u16_be(&mut self) -> u16
Reads a big endian u16
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn try_read_u16_le(&mut self) -> Result<u16>
Attempts to read a little endian u16
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn try_read_u16_be(&mut self) -> Result<u16>
Attempts to read a big endian u16
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_i16_le(&mut self) -> i16
Reads a little endian i16
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn read_i16_be(&mut self) -> i16
Reads a big endian i16
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn try_read_i16_le(&mut self) -> Result<i16>
Attempts to read a little endian i16
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn try_read_i16_be(&mut self) -> Result<i16>
Attempts to read a little endian i16
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_u32_le(&mut self) -> u32
Reads a little endian u32
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn read_u32_be(&mut self) -> u32
Reads a big endian u32
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn try_read_u32_le(&mut self) -> Result<u32>
Attempts to read a little endian u32
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn try_read_u32_be(&mut self) -> Result<u32>
Attempts to read a big endian u32
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_i32_le(&mut self) -> i32
Reads a little endian i32
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn read_i32_be(&mut self) -> i32
Reads a big endian i32
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn try_read_i32_le(&mut self) -> Result<i32>
Attempts to read a little endian i32
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn try_read_i32_be(&mut self) -> Result<i32>
Attempts to read a big endian i32
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_u64_le(&mut self) -> u64
Reads a little endian u64
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn read_u64_be(&mut self) -> u64
Reads a big endian u64
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn try_read_u64_le(&mut self) -> Result<u64>
Attempts to read a little endian u64
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn try_read_u64_be(&mut self) -> Result<u64>
Attempts to read a big endian u64
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_i64_le(&mut self) -> i64
Reads a little endian i64
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn read_i64_be(&mut self) -> i64
Reads a big endian i64
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn try_read_i64_le(&mut self) -> Result<i64>
Attempts to read a little endian i64
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn try_read_i64_be(&mut self) -> Result<i64>
Attempts to read a big endian i64
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_u128_le(&mut self) -> u128
Reads a little endian u128
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn read_u128_be(&mut self) -> u128
Reads a big endian u128
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn try_read_u128_le(&mut self) -> Result<u128>
Attempts to read a little endian u128
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn try_read_u128_be(&mut self) -> Result<u128>
Attempts to read a big endian u128
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_i128_le(&mut self) -> i128
Reads a little endian i128
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn read_i128_be(&mut self) -> i128
Reads a big endian i128
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn try_read_i128_le(&mut self) -> Result<i128>
Attempts to read a little endian i128
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn try_read_i128_be(&mut self) -> Result<i128>
Attempts to read a big endian i128
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_f32_le(&mut self) -> f32
Reads a little endian IEEE754 f32
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn read_f32_be(&mut self) -> f32
Reads a big endian IEEE754 f32
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn try_read_f32_le(&mut self) -> Result<f32>
Attempts to read a little endian IEEE754 f32
from the underlying
buffer.
If there are not enough bytes in self
this function will return
Error::EndOfStream
.
fn try_read_f32_be(&mut self) -> Result<f32>
Attempts to read a big endian IEEE754 f32
from the underlying buffer.
If there are not enough bytes in self
this function will return
Error::EndOfStream
.
fn read_f64_le(&mut self) -> f64
Reads a little endian IEEE754 f64
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn read_f64_be(&mut self) -> f64
Reads a big endian IEEE754 f64
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn try_read_f64_le(&mut self) -> Result<f64>
Attempts to read a little endian IEEE754 f64
from the underlying
buffer.
If there are not enough bytes in self
this function will return
Error::EndOfStream
.
fn try_read_f64_be(&mut self) -> Result<f64>
Attempts to read a big endian IEEE754 f64
from the underlying buffer.
If there are not enough bytes in self
this function will return
Error::EndOfStream
.