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

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

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());

Read a single byte from the Buf

Implementors