[−][src]Struct baffa::stack::Buffer
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]
fn capacity(&self) -> usize
[src]
fn len(&self) -> usize
[src]
fn iter(&self) -> Iter<Self>
[src]
fn iter_mut(&mut self) -> IterMut<Self>
[src]
impl<S: Sized> ContBuf for Buffer<S>
[src]
fn as_read_slice(&self) -> &[u8]
[src]
fn as_read_slice_mut(&mut self) -> &mut [u8]
[src]
fn as_write_slice(&mut self) -> &mut [MaybeUninit<u8>]
[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.
fn index(&self, index: usize) -> &Self::Output
[src]
impl<S: Sized> IndexMut<usize> for Buffer<S>
[src]
impl<S: Sized> ReadBuf for Buffer<S>
[src]
unsafe fn consume(&mut self, step: usize)
[src]
unsafe fn read(&mut self, ptr: *mut u8, size: usize)
[src]
fn available(&self) -> usize
[src]
fn read_slice(&mut self, bytes: &mut [u8]) -> usize
[src]
impl<S: Sized> WriteBuf for Buffer<S>
[src]
Auto Trait Implementations
impl<T> Send for Buffer<T> where
T: Send,
T: Send,
impl<T> Sync for Buffer<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Buffer<T> where
T: Unpin,
T: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ReadBufExt for T where
T: ReadBuf,
[src]
T: ReadBuf,
fn read_value<T: Copy + Sized>(&mut self, val: &mut MaybeUninit<T>) -> usize
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> WriteBufExt for T where
T: WriteBuf,
[src]
T: WriteBuf,