Trait bytes::buf::Buf [] [src]

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

    fn has_remaining(&self) -> bool { ... }
    fn read_slice(&mut self, dst: &mut [u8]) -> usize { ... }
    fn read_byte(&mut self) -> Option<u8> { ... }
}

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

Required Methods

fn remaining(&self) -> usize

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

fn bytes<'a>(&'a self) -> &'a [u8]

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

fn advance(&mut self, cnt: usize)

Advance the internal cursor of the Buf

Provided Methods

fn has_remaining(&self) -> bool

Returns true if there are any more bytes to consume

fn read_slice(&mut self, dst: &mut [u8]) -> usize

Read bytes from the Buf into the given slice and advance the cursor by the number of bytes read. Returns the number of bytes read.

use bytes::{SliceBuf, Buf};

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

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

fn read_byte(&mut self) -> Option<u8>

Read a single byte from the Buf

Implementors