Struct RingBuf

Source
pub struct RingBuf { /* private fields */ }
Expand description

A data structure that uses a single, fixed-size buffer as if it were connected end-to-end

Implementations§

Source§

impl RingBuf

Source

pub fn with_capacity(value: NonZeroUsize) -> Self

Create a new RingBuf object with provided capacity.

The provided capacity must be NonZeroUsize.

Source

pub fn remaining(&self) -> usize

Returns the number of bytes can be read.

Source

pub fn remaining_mut(&self) -> usize

Returns the number of bytes that can be written from the current position until the end of the buffer is reached.

Source

pub fn chunk_mut(&mut self) -> &mut [u8]

Returns a mutable slice starting at the write pointer, the length may shorter than remaining_mut.

Source

pub fn chunk(&self) -> &[u8]

Returns a immutable slice starting at the read pointer, the length may shorter than remaining.

Source

pub fn advance_mut(&mut self, offset: usize)

Advance the innner write cursor of this RingBuf.

if the offset value > remaining_mut will cause an panic.

Source

pub fn advance(&mut self, offset: usize)

Advance the innner read cursor of this RingBuf.

if the offset value > remaining will cause an panic.

Source

pub fn write(&mut self, buf: &[u8]) -> usize

Write data into ring buf.

Returns the number of written bytes. the number of written bytes returned can be shorter than the length of the input buffer when the ring buf doesn’t have enough capacity.

Source

pub fn read(&mut self, buf: &mut [u8]) -> usize

Read data from RingBuf and copy to provided mutable slice.

Returns the number of read bytes.

Auto Trait Implementations§

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.