[][src]Trait byteio::ReadBytesExt

pub trait ReadBytesExt<'a>: ReadBytes<'a> {
    fn read_u8(&mut self) -> u8 { ... }
fn try_read_u8(&mut self) -> Result<u8> { ... }
fn read_i8(&mut self) -> i8 { ... }
fn try_read_i8(&mut self) -> Result<i8> { ... }
fn read_u16<E: ByteOrder>(&mut self) -> u16 { ... }
fn try_read_u16<E: ByteOrder>(&mut self) -> Result<u16> { ... }
fn read_i16<E: ByteOrder>(&mut self) -> i16 { ... }
fn try_read_i16<E: ByteOrder>(&mut self) -> Result<i16> { ... }
fn read_u32<E: ByteOrder>(&mut self) -> u32 { ... }
fn try_read_u32<E: ByteOrder>(&mut self) -> Result<u32> { ... }
fn read_i32<E: ByteOrder>(&mut self) -> i32 { ... }
fn try_read_i32<E: ByteOrder>(&mut self) -> Result<i32> { ... }
fn read_u64<E: ByteOrder>(&mut self) -> u64 { ... }
fn try_read_u64<E: ByteOrder>(&mut self) -> Result<u64> { ... }
fn read_i64<E: ByteOrder>(&mut self) -> i64 { ... }
fn try_read_i64<E: ByteOrder>(&mut self) -> Result<i64> { ... }
fn read_u128<E: ByteOrder>(&mut self) -> u128 { ... }
fn try_read_u128<E: ByteOrder>(&mut self) -> Result<u128> { ... }
fn read_i128<E: ByteOrder>(&mut self) -> i128 { ... }
fn try_read_i128<E: ByteOrder>(&mut self) -> Result<i128> { ... }
fn read_f32<E: ByteOrder>(&mut self) -> f32 { ... }
fn try_read_f32<E: ByteOrder>(&mut self) -> Result<f32> { ... }
fn read_f64<E: ByteOrder>(&mut self) -> f64 { ... }
fn try_read_f64<E: ByteOrder>(&mut self) -> Result<f64> { ... } }

Extends ReadBytes with functions for reading numbers.

Examples

Read u16s from a buffer using native endianness:

use byteio::ReadBytesExt;
use byteorder::NativeEndian;

fn main() {
    let mut buf = &[0_u8, 1, 1, 0][..];

    let a = buf.read_u16::<NativeEndian>();
    let b = buf.read_u16::<NativeEndian>();

    assert!(buf.is_empty());
}

Try to read u16s from a buffer using a specific endianness:

use byteio::ReadBytesExt;
use byteorder::{BigEndian, LittleEndian};

fn main() -> byteio::Result<()> {
    let mut buf = &[0_u8, 1, 1, 0][..];

    let a = buf.try_read_u16::<BigEndian>()?;
    let b = buf.try_read_u16::<LittleEndian>()?;

    assert_eq!(a, 1);
    assert_eq!(b, 1);

    assert!(buf.is_empty());

    Ok(())
}

Provided methods

fn read_u8(&mut self) -> u8

Reads a u8 from the underlying buffer.

Panics

Panics if there are not enough bytes in self.

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

Reads an i8 from the underlying buffer.

Panics

Panics if there are not enough bytes in self.

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<E: ByteOrder>(&mut self) -> u16

Reads a u16 from the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_read_u16<E: ByteOrder>(&mut self) -> Result<u16>

Attempts to read a u16 from the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn read_i16<E: ByteOrder>(&mut self) -> i16

Reads an i16 from the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_read_i16<E: ByteOrder>(&mut self) -> Result<i16>

Attempts to read an i16 from the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn read_u32<E: ByteOrder>(&mut self) -> u32

Reads a u32 from the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_read_u32<E: ByteOrder>(&mut self) -> Result<u32>

Attempts to read a u32 from the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn read_i32<E: ByteOrder>(&mut self) -> i32

Reads an i32 from the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_read_i32<E: ByteOrder>(&mut self) -> Result<i32>

Attempts to read an i32 from the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn read_u64<E: ByteOrder>(&mut self) -> u64

Reads a u64 from the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_read_u64<E: ByteOrder>(&mut self) -> Result<u64>

Attempts to read a u64 from the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn read_i64<E: ByteOrder>(&mut self) -> i64

Reads an i64 from the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_read_i64<E: ByteOrder>(&mut self) -> Result<i64>

Attempts to read an i64 from the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn read_u128<E: ByteOrder>(&mut self) -> u128

Reads a u128 from the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_read_u128<E: ByteOrder>(&mut self) -> Result<u128>

Attempts to read a u128 from the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn read_i128<E: ByteOrder>(&mut self) -> i128

Reads an i128 from the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_read_i128<E: ByteOrder>(&mut self) -> Result<i128>

Attempts to read an i128 from the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn read_f32<E: ByteOrder>(&mut self) -> f32

Reads an IEEE754 f32 from the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_read_f32<E: ByteOrder>(&mut self) -> Result<f32>

Attempts to read an IEEE754 f32 from the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn read_f64<E: ByteOrder>(&mut self) -> f64

Reads an IEEE754 f64 from the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_read_f64<E: ByteOrder>(&mut self) -> Result<f64>

Attempts to read an IEEE754 f64 from the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

Loading content...

Implementors

impl<'a, R: ReadBytes<'a>> ReadBytesExt<'a> for R[src]

fn read_u8(&mut self) -> u8[src]

fn try_read_u8(&mut self) -> Result<u8>[src]

fn read_i8(&mut self) -> i8[src]

fn try_read_i8(&mut self) -> Result<i8>[src]

fn read_u16<E: ByteOrder>(&mut self) -> u16[src]

fn try_read_u16<E: ByteOrder>(&mut self) -> Result<u16>[src]

fn read_i16<E: ByteOrder>(&mut self) -> i16[src]

fn try_read_i16<E: ByteOrder>(&mut self) -> Result<i16>[src]

fn read_u32<E: ByteOrder>(&mut self) -> u32[src]

fn try_read_u32<E: ByteOrder>(&mut self) -> Result<u32>[src]

fn read_i32<E: ByteOrder>(&mut self) -> i32[src]

fn try_read_i32<E: ByteOrder>(&mut self) -> Result<i32>[src]

fn read_u64<E: ByteOrder>(&mut self) -> u64[src]

fn try_read_u64<E: ByteOrder>(&mut self) -> Result<u64>[src]

fn read_i64<E: ByteOrder>(&mut self) -> i64[src]

fn try_read_i64<E: ByteOrder>(&mut self) -> Result<i64>[src]

fn read_u128<E: ByteOrder>(&mut self) -> u128[src]

fn try_read_u128<E: ByteOrder>(&mut self) -> Result<u128>[src]

fn read_i128<E: ByteOrder>(&mut self) -> i128[src]

fn try_read_i128<E: ByteOrder>(&mut self) -> Result<i128>[src]

fn read_f32<E: ByteOrder>(&mut self) -> f32[src]

fn try_read_f32<E: ByteOrder>(&mut self) -> Result<f32>[src]

fn read_f64<E: ByteOrder>(&mut self) -> f64[src]

fn try_read_f64<E: ByteOrder>(&mut self) -> Result<f64>[src]

Loading content...