[][src]Type Definition tranche::BufTranche

type BufTranche<'a> = Tranche<'a, u8>;

A tranche of bytes, equipped with many convenience methods.

This type implements std::io::Read and std::io::BufRead when the std feature is enabled.

Methods

impl<'a> BufTranche<'a>[src]

pub fn take_front_as<T>(
    &mut self,
    n: usize
) -> Result<Tranche<'a, T>, UnexpectedEndError> where
    T: AlwaysAligned + AlwaysValid + Immutable, 
[src]

Takes the first n elements of type T out of the tranche.

Returns a new tranche with the first n elements of self viewed as a tranche of T values, or Err(_) if it is not long enough. The error details are expressed in terms of the size of T, not the size of u8.

Examples

let mut v = BufTranche::new(&[1, 2, 3, 4, 5, 6, 7, 8, 9]);
let four_pairs = v.take_front_as::<[u8; 2]>(4).unwrap();
assert_eq!(four_pairs.as_slice(), &[[1, 2], [3, 4], [5, 6], [7, 8]]);
assert_eq!(v.as_slice(), &[9]);

let err = v.take_front_as::<[u8; 2]>(1).unwrap_err();
assert_eq!(err.needed(), 1);
assert_eq!(err.len(), 0);

impl<'_> BufTranche<'_>[src]

pub fn take_u8(&mut self) -> Result<u8, UnexpectedEndError>[src]

Takes the first u8 out of the tranche.

Returns Err(_) if self is not long enough.

pub fn take_i8(&mut self) -> Result<i8, UnexpectedEndError>[src]

Takes the first i8 out of the tranche.

Returns Err(_) if self is not long enough.

pub fn take_u16_ne(&mut self) -> Result<u16, UnexpectedEndError>[src]

Returns a u16 by taking the first mem::size_of::<u16>() bytes out of the tranche in native endian order.

Returns Err(_) if self is not long enough.

pub fn take_u16_le(&mut self) -> Result<u16, UnexpectedEndError>[src]

Returns a u16 by taking the first mem::size_of::<u16>() bytes out of the tranche in little endian order.

Returns Err(_) if self is not long enough.

pub fn take_u16_be(&mut self) -> Result<u16, UnexpectedEndError>[src]

Returns a u16 by taking the first mem::size_of::<u16>() bytes out of the tranche in big endian order.

Returns Err(_) if self is not long enough.

pub fn take_i16_ne(&mut self) -> Result<i16, UnexpectedEndError>[src]

Returns a i16 by taking the first mem::size_of::<i16>() bytes out of the tranche in native endian order.

Returns Err(_) if self is not long enough.

pub fn take_i16_le(&mut self) -> Result<i16, UnexpectedEndError>[src]

Returns a i16 by taking the first mem::size_of::<i16>() bytes out of the tranche in little endian order.

Returns Err(_) if self is not long enough.

pub fn take_i16_be(&mut self) -> Result<i16, UnexpectedEndError>[src]

Returns a i16 by taking the first mem::size_of::<i16>() bytes out of the tranche in big endian order.

Returns Err(_) if self is not long enough.

pub fn take_u32_ne(&mut self) -> Result<u32, UnexpectedEndError>[src]

Returns a u32 by taking the first mem::size_of::<u32>() bytes out of the tranche in native endian order.

Returns Err(_) if self is not long enough.

pub fn take_u32_le(&mut self) -> Result<u32, UnexpectedEndError>[src]

Returns a u32 by taking the first mem::size_of::<u32>() bytes out of the tranche in little endian order.

Returns Err(_) if self is not long enough.

pub fn take_u32_be(&mut self) -> Result<u32, UnexpectedEndError>[src]

Returns a u32 by taking the first mem::size_of::<u32>() bytes out of the tranche in big endian order.

Returns Err(_) if self is not long enough.

pub fn take_i32_ne(&mut self) -> Result<i32, UnexpectedEndError>[src]

Returns a i32 by taking the first mem::size_of::<i32>() bytes out of the tranche in native endian order.

Returns Err(_) if self is not long enough.

pub fn take_i32_le(&mut self) -> Result<i32, UnexpectedEndError>[src]

Returns a i32 by taking the first mem::size_of::<i32>() bytes out of the tranche in little endian order.

Returns Err(_) if self is not long enough.

pub fn take_i32_be(&mut self) -> Result<i32, UnexpectedEndError>[src]

Returns a i32 by taking the first mem::size_of::<i32>() bytes out of the tranche in big endian order.

Returns Err(_) if self is not long enough.

pub fn take_u64_ne(&mut self) -> Result<u64, UnexpectedEndError>[src]

Returns a u64 by taking the first mem::size_of::<u64>() bytes out of the tranche in native endian order.

Returns Err(_) if self is not long enough.

pub fn take_u64_le(&mut self) -> Result<u64, UnexpectedEndError>[src]

Returns a u64 by taking the first mem::size_of::<u64>() bytes out of the tranche in little endian order.

Returns Err(_) if self is not long enough.

pub fn take_u64_be(&mut self) -> Result<u64, UnexpectedEndError>[src]

Returns a u64 by taking the first mem::size_of::<u64>() bytes out of the tranche in big endian order.

Returns Err(_) if self is not long enough.

pub fn take_i64_ne(&mut self) -> Result<i64, UnexpectedEndError>[src]

Returns a i64 by taking the first mem::size_of::<i64>() bytes out of the tranche in native endian order.

Returns Err(_) if self is not long enough.

pub fn take_i64_le(&mut self) -> Result<i64, UnexpectedEndError>[src]

Returns a i64 by taking the first mem::size_of::<i64>() bytes out of the tranche in little endian order.

Returns Err(_) if self is not long enough.

pub fn take_i64_be(&mut self) -> Result<i64, UnexpectedEndError>[src]

Returns a i64 by taking the first mem::size_of::<i64>() bytes out of the tranche in big endian order.

Returns Err(_) if self is not long enough.

pub fn take_u128_ne(&mut self) -> Result<u128, UnexpectedEndError>[src]

Returns a u128 by taking the first mem::size_of::<u128>() bytes out of the tranche in native endian order.

Returns Err(_) if self is not long enough.

pub fn take_u128_le(&mut self) -> Result<u128, UnexpectedEndError>[src]

Returns a u128 by taking the first mem::size_of::<u128>() bytes out of the tranche in little endian order.

Returns Err(_) if self is not long enough.

pub fn take_u128_be(&mut self) -> Result<u128, UnexpectedEndError>[src]

Returns a u128 by taking the first mem::size_of::<u128>() bytes out of the tranche in big endian order.

Returns Err(_) if self is not long enough.

pub fn take_i128_ne(&mut self) -> Result<i128, UnexpectedEndError>[src]

Returns a i128 by taking the first mem::size_of::<i128>() bytes out of the tranche in native endian order.

Returns Err(_) if self is not long enough.

pub fn take_i128_le(&mut self) -> Result<i128, UnexpectedEndError>[src]

Returns a i128 by taking the first mem::size_of::<i128>() bytes out of the tranche in little endian order.

Returns Err(_) if self is not long enough.

pub fn take_i128_be(&mut self) -> Result<i128, UnexpectedEndError>[src]

Returns a i128 by taking the first mem::size_of::<i128>() bytes out of the tranche in big endian order.

Returns Err(_) if self is not long enough.

pub fn take_usize_ne(&mut self) -> Result<usize, UnexpectedEndError>[src]

Returns a usize by taking the first mem::size_of::<usize>() bytes out of the tranche in native endian order.

Returns Err(_) if self is not long enough.

pub fn take_usize_le(&mut self) -> Result<usize, UnexpectedEndError>[src]

Returns a usize by taking the first mem::size_of::<usize>() bytes out of the tranche in little endian order.

Returns Err(_) if self is not long enough.

pub fn take_usize_be(&mut self) -> Result<usize, UnexpectedEndError>[src]

Returns a usize by taking the first mem::size_of::<usize>() bytes out of the tranche in big endian order.

Returns Err(_) if self is not long enough.

pub fn take_isize_ne(&mut self) -> Result<isize, UnexpectedEndError>[src]

Returns a isize by taking the first mem::size_of::<isize>() bytes out of the tranche in native endian order.

Returns Err(_) if self is not long enough.

pub fn take_isize_le(&mut self) -> Result<isize, UnexpectedEndError>[src]

Returns a isize by taking the first mem::size_of::<isize>() bytes out of the tranche in little endian order.

Returns Err(_) if self is not long enough.

pub fn take_isize_be(&mut self) -> Result<isize, UnexpectedEndError>[src]

Returns a isize by taking the first mem::size_of::<isize>() bytes out of the tranche in big endian order.

Returns Err(_) if self is not long enough.

Trait Implementations

impl<'_> BufRead for BufTranche<'_>[src]

impl<'_> Read for BufTranche<'_>[src]