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 const fn as_mut_slice(&mut self) -> &mut [T] ⓘ
pub const 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.
Trait Implementations§
Source§impl<'a, T: Clone, S: Clone> Clone for BufferViewExample<'a, T, S>
impl<'a, T: Clone, S: Clone> Clone for BufferViewExample<'a, T, S>
Source§fn clone(&self) -> BufferViewExample<'a, T, S>
fn clone(&self) -> BufferViewExample<'a, T, S>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<'a, T: Copy, S: Copy> Copy for BufferViewExample<'a, T, S>
impl<'a, T: Eq, S: Eq> Eq for BufferViewExample<'a, T, S>
Source§impl<'a, T: Ord, S: Ord> Ord for BufferViewExample<'a, T, S>
impl<'a, T: Ord, S: Ord> Ord for BufferViewExample<'a, T, S>
Source§fn cmp(&self, other: &BufferViewExample<'a, T, S>) -> Ordering
fn cmp(&self, other: &BufferViewExample<'a, T, S>) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<'a, T: PartialEq, S: PartialEq> PartialEq for BufferViewExample<'a, T, S>
impl<'a, T: PartialEq, S: PartialEq> PartialEq for BufferViewExample<'a, T, S>
Source§fn eq(&self, other: &BufferViewExample<'a, T, S>) -> bool
fn eq(&self, other: &BufferViewExample<'a, T, S>) -> bool
self and other values to be equal, and is used by ==.Source§impl<'a, T: PartialOrd, S: PartialOrd> PartialOrd for BufferViewExample<'a, T, S>
impl<'a, T: PartialOrd, S: PartialOrd> PartialOrd for BufferViewExample<'a, T, S>
impl<'a, T, S> StructuralPartialEq for BufferViewExample<'a, T, S>
Auto Trait Implementations§
impl<'a, T, S> Freeze for BufferViewExample<'a, T, S>where
S: Freeze,
impl<'a, T, S> RefUnwindSafe for BufferViewExample<'a, T, S>where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<'a, T, S> Send for BufferViewExample<'a, T, S>
impl<'a, T, S> Sync for BufferViewExample<'a, T, S>
impl<'a, T, S> Unpin for BufferViewExample<'a, T, S>where
S: Unpin,
impl<'a, T, S> UnsafeUnpin for BufferViewExample<'a, T, S>where
S: UnsafeUnpin,
impl<'a, T, S> UnwindSafe for BufferViewExample<'a, T, S>where
S: UnwindSafe,
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> AnyExt for T
impl<T> AnyExt for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId of Self using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
alloc only.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> MemExt for Twhere
T: ?Sized,
impl<T> MemExt for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Source§fn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice only.