pub struct BufferViewExample<'a, T, S> { /* private fields */ }_docs_examples only.Expand description
✨ 🗃️
A linear buffer view over contiguous storage, made with buffer_linear!.
§Methods
-
Exclusive slice (
slice_mut)- Constructors:
try_new,new_truncatedtry_from_slice,from_slice_with,from_slice_truncated. - Capacity:
capacity(_prim),remaining_capacity(_prim),is_full. - Logical range control:
clear,truncate, (_prim). - Push:
push_back(_copy),push_slice(_copy, _copy_exact). - Pop:
pop_back_clone,pop_back_copy. - Peek:
peek_back(_mut). - Get:
get(_mut). - Views:
as_slice(_mut), - Iteration:
iter(_mut). - Visitation:
visit_each(_mut),visit_slice(_mut).
- Constructors:
-
Shared slice (
slice)- Constructors:
try_from_slice,from_slice_with,from_slice_truncated. - Capacity:
capacity(_prim),remaining_capacity(_prim),is_full. - Peek:
peek_back. - Get:
get. - Views:
as_slice. - Iteration:
iter. - Visitation:
visit_each,visit_slice.
- Constructors:
Implementations§
Source§impl<'a, T, S> BufferViewExample<'a, T, S>
Common methods.
impl<'a, T, S> BufferViewExample<'a, T, S>
Common methods.
Source§impl<'a, T> BufferViewExample<'a, T, &'a mut [T]>
Buffer view over an exclusive slice.
impl<'a, T> BufferViewExample<'a, T, &'a mut [T]>
Buffer view over an exclusive slice.
§Invariants
- Elements are stored in
storage[0 .. len) len <= storage.len()
§Notes
- This type does not own its elements
- Shrinking the buffer does not drop values, but mutating may overwrite.
Sourcepub const fn try_new(slice: &'a mut [T]) -> Option<Self> ⓘ
pub const fn try_new(slice: &'a mut [T]) -> Option<Self> ⓘ
Creates an empty buffer using the entire slice as backing storage.
Returns None if the slice length cannot be represented by the index type.
Sourcepub const fn new_truncated(slice: &'a mut [T]) -> Self
pub const fn new_truncated(slice: &'a mut [T]) -> Self
Creates an empty buffer, truncating the backing slice if it exceeds what the index type can represent.
Sourcepub const fn try_from_slice(slice: &'a mut [T]) -> Option<Self> ⓘ
pub const fn try_from_slice(slice: &'a mut [T]) -> Option<Self> ⓘ
Creates a buffer over an exclusive slice.
Returns None if the slice length cannot be represented by the index type.
Sourcepub const fn from_slice_with(
slice: &'a mut [T],
len: NonValueU8<{ u8::MAX }>,
) -> Option<Self> ⓘ
pub const fn from_slice_with( slice: &'a mut [T], len: NonValueU8<{ u8::MAX }>, ) -> Option<Self> ⓘ
Creates a buffer over an exclusive slice with an explicit logical length.
Returns None if len > slice.len() or cannot be represented by the index type.
Sourcepub const fn from_slice_truncated(slice: &'a mut [T]) -> Self
pub const fn from_slice_truncated(slice: &'a mut [T]) -> Self
Creates a buffer over an exclusive slice, truncating the visible active range if the slice length exceeds what the index type can represent.
Sourcepub const fn capacity(&self) -> NonValueU8<{ u8::MAX }>
pub const fn capacity(&self) -> NonValueU8<{ u8::MAX }>
Returns the capacity of the underlying slice storage.
Sourcepub const fn capacity_prim(&self) -> u8
pub const fn capacity_prim(&self) -> u8
Returns the capacity of the underlying slice storage.
Sourcepub const fn remaining_capacity(&self) -> NonValueU8<{ u8::MAX }>
pub const fn remaining_capacity(&self) -> NonValueU8<{ u8::MAX }>
Returns the number of additional elements that fit within the current capacity.
Sourcepub const fn remaining_capacity_prim(&self) -> u8
pub const fn remaining_capacity_prim(&self) -> u8
Returns the number of additional elements that fit within the current capacity.
Sourcepub const fn truncate(&mut self, new_len: NonValueU8<{ u8::MAX }>)
pub const fn truncate(&mut self, new_len: NonValueU8<{ u8::MAX }>)
Sets the logical length to min(new_len, len).
If new_len >= len, this is a no-op.
Sourcepub const fn truncate_prim(&mut self, new_len: u8) -> Result<(), InvalidValue> ⓘ
pub const fn truncate_prim(&mut self, new_len: u8) -> Result<(), InvalidValue> ⓘ
Primitive-index variant of truncate,
Sourcepub fn push_back(&mut self, value: T) -> Result<(), T> ⓘ
pub fn push_back(&mut self, value: T) -> Result<(), T> ⓘ
Appends a value to the back of the buffer.
Returns Err(value) if the buffer is full.
Sourcepub const fn push_back_copy(&mut self, value: T) -> Result<(), T> ⓘwhere
T: Copy,
pub const fn push_back_copy(&mut self, value: T) -> Result<(), T> ⓘwhere
T: Copy,
Appends a copy of value to the back of the buffer.
Returns Err(value) if the buffer is full.
Sourcepub fn push_slice(&mut self, src: &[T]) -> usizewhere
T: Clone,
pub fn push_slice(&mut self, src: &[T]) -> usizewhere
T: Clone,
Appends as many elements cloned from src as fit.
Returns the number of elements appended.
Sourcepub const fn push_slice_copy(&mut self, src: &[T]) -> usizewhere
T: Copy,
pub const fn push_slice_copy(&mut self, src: &[T]) -> usizewhere
T: Copy,
Appends as many copied elements from src as fit.
Returns the number of elements appended.
Sourcepub const fn push_slice_copy_exact(&mut self, src: &[T]) -> Result<(), usize> ⓘwhere
T: Copy,
pub const fn push_slice_copy_exact(&mut self, src: &[T]) -> Result<(), usize> ⓘwhere
T: Copy,
Appends all copied elements from src, or none if insufficient capacity.
Returns Err(remaining_capacity) if not enough space is available.
Sourcepub fn pop_back_clone(&mut self) -> Option<T> ⓘwhere
T: Clone,
pub fn pop_back_clone(&mut self) -> Option<T> ⓘwhere
T: Clone,
Removes and returns a cloned value from the back of the buffer.
Sourcepub const fn pop_back_copy(&mut self) -> Option<T> ⓘwhere
T: Copy,
pub const fn pop_back_copy(&mut self) -> Option<T> ⓘwhere
T: Copy,
Removes and returns a copied value from the back of the buffer.
Sourcepub const fn peek_back(&self) -> Option<&T> ⓘ
pub const fn peek_back(&self) -> Option<&T> ⓘ
Returns a shared reference to the last element without removing it.
Sourcepub const fn peek_mut_back(&mut self) -> Option<&mut T> ⓘ
pub const fn peek_mut_back(&mut self) -> Option<&mut T> ⓘ
Returns an exclusive reference to the last element without removing it.
Sourcepub const fn get(&self, index: NonValueU8<{ u8::MAX }>) -> Option<&T> ⓘ
pub const fn get(&self, index: NonValueU8<{ u8::MAX }>) -> Option<&T> ⓘ
Returns a shared reference to the element at index, or None if out of bounds.
Sourcepub const fn get_mut(
&mut self,
index: NonValueU8<{ u8::MAX }>,
) -> Option<&mut T> ⓘ
pub const fn get_mut( &mut self, index: NonValueU8<{ u8::MAX }>, ) -> Option<&mut T> ⓘ
Returns an exclusive reference to the element at index,
or None if out of bounds.
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Returns the active logical range as a mutable slice.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>
Iterates mutably over the initialized elements.
Sourcepub fn visit_each<F>(&self, f: F)
pub fn visit_each<F>(&self, f: F)
Visits each initialized element without exposing borrow identity.
Sourcepub fn visit_each_mut<F>(&mut self, f: F)
pub fn visit_each_mut<F>(&mut self, f: F)
Visits each initialized element mutably without exposing borrow identity.
Sourcepub fn visit_slice<F, R>(&self, f: F) -> R
pub fn visit_slice<F, R>(&self, f: F) -> R
Visits the active logical range as a shared slice of Some(T),
without exposing borrow identity.
Sourcepub fn visit_mut_slice<F, R>(&mut self, f: F) -> R
pub fn visit_mut_slice<F, R>(&mut self, f: F) -> R
Visits the active logical range as an exclusive slice of Some(T),
without exposing borrow identity.
Source§impl<'a, T> BufferViewExample<'a, T, &'a [T]>
Read-only buffer view over a shared slice.
impl<'a, T> BufferViewExample<'a, T, &'a [T]>
Read-only buffer view over a shared slice.
§Invariants
- Elements are read from
storage[0 .. len) len <= storage.len()
§Notes
- This type does not own its elements
- No mutation or removal operations are supported
lenlimits the visible logical range
Sourcepub const fn try_from_slice(slice: &'a [T]) -> Option<Self> ⓘ
pub const fn try_from_slice(slice: &'a [T]) -> Option<Self> ⓘ
Creates a buffer over a shared slice.
Returns None if the slice length cannot be represented by the index type.
Sourcepub const fn from_slice_with(
slice: &'a [T],
len: NonValueU8<{ u8::MAX }>,
) -> Option<Self> ⓘ
pub const fn from_slice_with( slice: &'a [T], len: NonValueU8<{ u8::MAX }>, ) -> Option<Self> ⓘ
Creates a buffer over an exclusive slice with an explicit logical length.
Returns None if len > slice.len() or cannot be represented by the index type.
Sourcepub const fn from_slice_truncated(slice: &'a [T]) -> Self
pub const fn from_slice_truncated(slice: &'a [T]) -> Self
Creates a buffer over a shared slice, truncating the visible logical range if the slice length exceeds what the index type can represent.
Sourcepub const fn capacity(&self) -> NonValueU8<{ u8::MAX }>
pub const fn capacity(&self) -> NonValueU8<{ u8::MAX }>
Returns the capacity of the underlying slice storage.
Sourcepub const fn capacity_prim(&self) -> u8
pub const fn capacity_prim(&self) -> u8
Returns the capacity of the underlying slice storage.
Sourcepub const fn remaining_capacity(&self) -> NonValueU8<{ u8::MAX }>
pub const fn remaining_capacity(&self) -> NonValueU8<{ u8::MAX }>
Returns the number of additional elements that fit within the current capacity.
Sourcepub const fn remaining_capacity_prim(&self) -> u8
pub const fn remaining_capacity_prim(&self) -> u8
Returns the number of additional elements that fit within the current capacity.
Sourcepub const fn peek_back(&self) -> Option<&T> ⓘ
pub const fn peek_back(&self) -> Option<&T> ⓘ
Returns a shared reference to the last element without removing it.
Sourcepub const fn get(&self, index: NonValueU8<{ u8::MAX }>) -> Option<&T> ⓘ
pub const fn get(&self, index: NonValueU8<{ u8::MAX }>) -> Option<&T> ⓘ
Returns a shared reference to the element at index, or None if out of bounds.
Sourcepub fn visit_each<F>(&self, f: F)
pub fn visit_each<F>(&self, f: F)
Visits each initialized element without exposing borrow identity.
Sourcepub fn visit_slice<F, R>(&self, f: F) -> R
pub fn visit_slice<F, R>(&self, f: F) -> R
Visits the active logical range as a shared slice without exposing borrow identity.