Trait bytes::Buf [] [src]

pub trait Buf {
    fn remaining(&self) -> usize;
    fn bytes(&self) -> &[u8];
    fn advance(&mut self, cnt: usize);

    fn has_remaining(&self) -> bool { ... }
    fn copy_to<S: Sink + ?Sized>(&mut self, dst: &mut S) where Self: Sized { ... }
    fn copy_to_slice(&mut self, dst: &mut [u8]) { ... }
    fn peek_u8(&self) -> Option<u8> { ... }
    fn get_u8(&mut self) -> u8 { ... }
    fn get_i8(&mut self) -> i8 { ... }
    fn get_u16<T: ByteOrder>(&mut self) -> u16 { ... }
    fn get_i16<T: ByteOrder>(&mut self) -> i16 { ... }
    fn get_u32<T: ByteOrder>(&mut self) -> u32 { ... }
    fn get_i32<T: ByteOrder>(&mut self) -> i32 { ... }
    fn get_u64<T: ByteOrder>(&mut self) -> u64 { ... }
    fn get_i64<T: ByteOrder>(&mut self) -> i64 { ... }
    fn get_uint<T: ByteOrder>(&mut self, nbytes: usize) -> u64 { ... }
    fn get_int<T: ByteOrder>(&mut self, nbytes: usize) -> i64 { ... }
    fn get_f32<T: ByteOrder>(&mut self) -> f32 { ... }
    fn get_f64<T: ByteOrder>(&mut self) -> f64 { ... }
    fn by_ref(&mut self) -> &mut Self where Self: Sized { ... }
    fn take(self, limit: usize) -> Take<Self> where Self: Sized { ... }
    fn reader(self) -> Reader<Self> where Self: Sized { ... }
}

A trait for values that provide sequential read access to bytes.

Required Methods

Returns the number of bytes that can be accessed from the Buf

Returns a slice starting at the current Buf position and of length between 0 and Buf::remaining().

Advance the internal cursor of the Buf

Provided Methods

Returns true if there are any more bytes to consume

Copies bytes from self into dst

Panics

The function panics if self does not contain enough bytes to fill dst.

Copies bytes from the Buf into the given slice and advance the cursor by the number of bytes copied.

use std::io::Cursor;
use bytes::Buf;

let mut buf = Cursor::new(b"hello world");
let mut dst = [0; 5];

buf.copy_to_slice(&mut dst);
assert_eq!(b"hello", &dst);
assert_eq!(6, buf.remaining());

Panics

This function panics if self.remaining() < dst.len()

Gets an unsigned 8 bit integer from the Buf without advancing the buffer cursor

Gets an unsigned 8 bit integer from the Buf.

Gets a signed 8 bit integer from the Buf.

Gets an unsigned 16 bit integer from the Buf

Gets a signed 16 bit integer from the Buf

Gets an unsigned 32 bit integer from the Buf

Gets a signed 32 bit integer from the Buf

Gets an unsigned 64 bit integer from the Buf

Gets a signed 64 bit integer from the Buf

Gets an unsigned n-bytes integer from the Buf

Gets a signed n-bytes integer from the Buf

Gets a IEEE754 single-precision (4 bytes) floating point number from the Buf

Gets a IEEE754 double-precision (8 bytes) floating point number from the Buf

Creates a "by reference" adaptor for this instance of Buf

Create an adapter which will limit at most limit bytes from it.

Return a Reader for the value. Allows using a Buf as an io::Read

Implementors