BufferReader

Struct BufferReader 

Source
pub struct BufferReader<'a>(/* private fields */);
Expand description

A zero-copy immutable byte-buffer reader.

Internally, it stores an offset that is increased during reading.

Implementations§

Source§

impl<'a> BufferReader<'a>

Source

pub fn new(buffer: &'a [u8]) -> Self

Creates a BufferReader from the given slice, without copying.

Inner offset is initialized to zero.

Source

pub fn capacity(&self) -> usize

Returns the remaining capacity in the buffer.

Source

pub fn offset(&self) -> usize

Returns the current offset of the buffer.

Source

pub fn skip(&mut self, len: usize) -> Result<(), EndOfBuffer>

Advances the offset.

In case of Err the offset is not advanced.

Source

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

Returns a reference to the internal buffer.

Note: this is the entire buffer (despite offset).

Source

pub fn buffer_remaining(&mut self) -> &'a [u8]

Returns the inner buffer starting from the current offset.

Source

pub fn child(&mut self) -> BufferReaderChild<'a, '_>

Creates a BufferReaderChild with this parent.

Trait Implementations§

Source§

impl<'a> BytesReader<'a> for BufferReader<'a>

Source§

fn get_varint(&mut self) -> Option<VarInt>

Reads an unsigned variable-length integer in network byte-order from the current offset and advances the offset. Read more
Source§

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

Reads len bytes from the current offset without copying and advances the offset. Read more
Source§

impl Debug for BufferReader<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for BufferReader<'a>

§

impl<'a> RefUnwindSafe for BufferReader<'a>

§

impl<'a> Send for BufferReader<'a>

§

impl<'a> Sync for BufferReader<'a>

§

impl<'a> Unpin for BufferReader<'a>

§

impl<'a> UnwindSafe for BufferReader<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.