pub trait BytesReadRef<'a>: BytesRead {
    // Required methods
    fn as_slice_ref(&self) -> &'a [u8] ;
    fn remaining_ref(&self) -> &'a [u8] ;
    fn try_read_ref(&mut self, len: usize) -> Result<&'a [u8], ReadError>;
    fn peek_ref(&self, len: usize) -> Option<&'a [u8]>;

    // Provided method
    fn read_ref(&mut self, len: usize) -> &'a [u8]  { ... }
}
Expand description

Read bytes while keeping the original reference.

use simple_bytes::{Bytes, BytesRead, BytesReadRef};

let mut bytes = Bytes::from("hey".as_ref());
let h = bytes.read_u8();
let ey: &'static [u8] = bytes.remaining_ref();

Required Methods§

source

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

Returns the entire slice.

source

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

Returns all remaining bytes.

source

fn try_read_ref(&mut self, len: usize) -> Result<&'a [u8], ReadError>

Try to read a given length of bytes.

Failes

If len exceeds self.remaining().len().

source

fn peek_ref(&self, len: usize) -> Option<&'a [u8]>

Tries to read a given length without updating the internal position. Returns None if there are not enought bytes remaining.

Provided Methods§

source

fn read_ref(&mut self, len: usize) -> &'a [u8]

Reads a given length of bytes.

Panics

If len exceeds self.remaining().len().

Implementations on Foreign Types§

source§

impl<'a, R: BytesReadRef<'a>> BytesReadRef<'a> for &mut R

source§

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

source§

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

source§

fn try_read_ref(&mut self, len: usize) -> Result<&'a [u8], ReadError>

source§

fn peek_ref(&self, len: usize) -> Option<&'a [u8]>

Implementors§

source§

impl<'a> BytesReadRef<'a> for Bytes<'a>