[][src]Struct baffa::stack::Buffer

pub struct Buffer<T: Sized> { /* fields omitted */ }

Static buffer to raw bytes

The size of the storage must be known at compile time, therefore it is suitable only for non-dynamic storages.

While write semantics are pretty obvious, read behaviour is more complicated due to it being a static buffer.

When performing ReadBuf::read memory is always being read from the beginning. So as with any other implementation read leads to consumption. But as this buffer is single chunk of static memory, such operation will require to shift already written bytes to the beginning (meaning each ReadBuf::consume involves a memmove unless consumed len is not equal to current len)

In general it would be more effective to access memory as slice and then consume it, if needed.

Implementations

impl<S: Sized> Buffer<S>[src]

pub const fn new() -> Self[src]

Creates new instance

pub const fn into_circular(self) -> Ring<S>[src]

Transforms buffer into ring buffer.

pub const unsafe fn from_parts(inner: MaybeUninit<S>, cursor: usize) -> Self[src]

Creates new instance from parts.

cursor - number of elements written. It is user responsibility to make sure it is not over actual capacity

pub const fn into_parts(self) -> (MaybeUninit<S>, usize)[src]

Splits buffer into parts.

pub const fn as_ptr(&self) -> *const u8[src]

Returns pointer to the beginning of underlying buffer

pub const fn remaining(&self) -> usize[src]

Returns number of bytes left (not written yet)

pub fn as_slice(&self) -> &[u8][src]

Returns slice to already written data.

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

Returns mutable slice to already written data.

pub fn truncate(&mut self, cursor: usize)[src]

Shortens the buffer.

Does nothing if new cursor is after current position.

pub unsafe fn set_len(&mut self, cursor: usize)[src]

Changes written length, without writing.

When used, user must guarantee that these bytes are written.

pub const fn capacity() -> usize[src]

Returns buffer overall capacity.

pub const fn len(&self) -> usize[src]

Returns number of bytes written.

Trait Implementations

impl<S: Sized> AsRef<[u8]> for Buffer<S>[src]

impl<S: Sized> Buf for Buffer<S>[src]

impl<S: Sized> ContBuf for Buffer<S>[src]

impl<S: Sized> Debug for Buffer<S>[src]

impl<S: Sized> Index<usize> for Buffer<S>[src]

type Output = u8

The returned type after indexing.

impl<S: Sized> IndexMut<usize> for Buffer<S>[src]

impl<S: Sized> ReadBuf for Buffer<S>[src]

impl<S: Sized> WriteBuf for Buffer<S>[src]

Auto Trait Implementations

impl<T> Send for Buffer<T> where
    T: Send

impl<T> Sync for Buffer<T> where
    T: Sync

impl<T> Unpin for Buffer<T> where
    T: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ReadBufExt for T where
    T: ReadBuf
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> WriteBufExt for T where
    T: WriteBuf
[src]