Trait ByteBuf

Source
pub trait ByteBuf: Buf {
    // Required methods
    fn peek_bytes(&mut self, r: Range<usize>) -> Bytes;
    fn get_bytes(&mut self, size: usize) -> Bytes;

    // Provided methods
    fn try_peek_bytes(
        &mut self,
        r: Range<usize>,
    ) -> Result<Bytes, NotEnoughBytesError> { ... }
    fn try_get_bytes(
        &mut self,
        size: usize,
    ) -> Result<Bytes, NotEnoughBytesError> { ... }
}
Expand description

Extension for working with bytes::Buf.

Required Methods§

Source

fn peek_bytes(&mut self, r: Range<usize>) -> Bytes

Peek ahead in the buffer by the provided range.

Source

fn get_bytes(&mut self, size: usize) -> Bytes

Get size bytes from the underlying buffer.

Provided Methods§

Source

fn try_peek_bytes( &mut self, r: Range<usize>, ) -> Result<Bytes, NotEnoughBytesError>

Try to peek ahead in the buffer by the provided range, returning an error if there are less bytes than the requested range.

Source

fn try_get_bytes(&mut self, size: usize) -> Result<Bytes, NotEnoughBytesError>

Try to get size bytes from the buffer, returning an error if there are less bytes than the requested number.

Implementations on Foreign Types§

Source§

impl ByteBuf for &[u8]

Source§

fn peek_bytes(&mut self, r: Range<usize>) -> Bytes

Source§

fn get_bytes(&mut self, size: usize) -> Bytes

Source§

impl ByteBuf for Bytes

Source§

fn peek_bytes(&mut self, r: Range<usize>) -> Bytes

Source§

fn get_bytes(&mut self, size: usize) -> Bytes

Source§

impl ByteBuf for BytesMut

Source§

fn peek_bytes(&mut self, r: Range<usize>) -> Bytes

Source§

fn get_bytes(&mut self, size: usize) -> Bytes

Source§

impl<T: AsRef<[u8]>> ByteBuf for Cursor<T>

Source§

fn peek_bytes(&mut self, r: Range<usize>) -> Bytes

Source§

fn get_bytes(&mut self, size: usize) -> Bytes

Source§

impl<T: ByteBuf> ByteBuf for &mut T

Implementors§