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

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

Loading content...

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

Loading content...

Implementations on Foreign Types

impl Buf for Box<dyn Buf + 'static>[src]

impl Buf for Cursor<Vec<u8>>[src]

impl<'a> Buf for Cursor<&'a [u8]>[src]

Loading content...

Implementors

impl Buf for ByteBuf[src]

impl Buf for ROByteBuf[src]

impl Buf for RingBuf[src]

impl Buf for RopeBuf[src]

impl Buf for SmallByteStrBuf[src]

impl<'a> Buf for SliceBuf<'a>[src]

impl<T: Buf> Buf for Take<T>[src]

Loading content...