Struct Ring

Source
pub struct Ring<T: Sized> { /* private fields */ }
Expand description

Circular version of Buffer

Because Buffer is circular, it always has remaining bytes to write. But care must be taken because without consuming already written bytes, it is easy to over-write as ring buffer always has capacity.

Implementations§

Source§

impl<S: Sized> Ring<S>

Source

pub const fn new() -> Self

Creates new instance

Source

pub const unsafe fn from_parts(buffer: Buffer<S>, read: usize) -> Self

Creates new instance from parts

Source

pub const fn into_parts(self) -> (Buffer<S>, usize)

Creates new instance from parts

Source

pub const fn len(&self) -> usize

Returns number of available elements

Source

pub const fn is_empty(&self) -> bool

Returns whether buffer is empty.

Source

pub const fn is_full(&self) -> bool

Returns whether buffer is full.

Trait Implementations§

Source§

impl<S: Sized> Buf for Ring<S>

Source§

fn capacity(&self) -> usize

Returns size of the underlying memory in the buffer.
Source§

fn len(&self) -> usize

Returns number of elements inside the buffer.
Source§

fn iter(&self) -> Iter<'_, Self>

Returns iterator over elements inside the buffer.
Source§

fn iter_mut(&mut self) -> IterMut<'_, Self>

Returns mutable iterator over elements inside the buffer.
Source§

impl<S: Sized> Index<usize> for Ring<S>

Source§

type Output = u8

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<S: Sized> IndexMut<usize> for Ring<S>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<S: Sized> ReadBuf for Ring<S>

Source§

fn available(&self) -> usize

Returns number of bytes left Read more
Source§

unsafe fn consume(&mut self, step: usize)

Moves cursor, considering bytes as consumed.
Source§

unsafe fn read(&mut self, ptr: *mut u8, size: usize)

Low level read function, that consumes available bytes up to size. Read more
Source§

fn read_slice(&mut self, bytes: &mut [u8]) -> usize

Reads available bytes into slice
Source§

impl<S: Sized> WriteBuf for Ring<S>

Source§

fn remaining(&self) -> usize

Returns number of bytes left Read more
Source§

unsafe fn advance(&mut self, step: usize)

Moves cursor, considering bytes written.
Source§

unsafe fn write(&mut self, ptr: *const u8, size: usize)

Low level write method, which copies data from pointer up to size. Read more
Source§

fn write_slice(&mut self, bytes: &[u8]) -> usize

Writes supplied slice into the buffer, returning number of written bytes. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Ring<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Ring<T>
where T: RefUnwindSafe,

§

impl<T> Send for Ring<T>
where T: Send,

§

impl<T> Sync for Ring<T>
where T: Sync,

§

impl<T> Unpin for Ring<T>
where T: Unpin,

§

impl<T> UnwindSafe for Ring<T>
where T: UnwindSafe,

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> ReadBufExt for T
where T: ReadBuf,

Source§

fn read_value<T: Copy + Sized>(&mut self, val: &mut MaybeUninit<T>) -> usize

Reads value into storage. Read more
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.
Source§

impl<T> WriteBufExt for T
where T: WriteBuf,

Source§

fn write_value<T: Copy + Sized>(&mut self, val: &T) -> usize

Writes supplied value by performing bit copy, advancing length and returning number of bytes written. Read more