pub struct BufferRingStaticExample<T, S> { /* private fields */ }_docs_examples only.Expand description
✨ 🗃️
A static ring buffer over contiguous storage, made with buffer_ring!.
§Methods
-
Fully initialized array (
array)- Constructors: new (_init), from_array (_empty, _full, _ring, _ring_prim), from_slice (_clone, _copy).
- Capacity: CAP (_PRIM), capacity (_prim), remaining_capacity (_prim), is_full.
- Logical range control: clear (_copy), truncate, (_prim).
- Push: push_back (_copy), push_back_slice (_copy, _copy_exact), push_front (_copy), push_front_slice (_copy, _copy_exact).
- Pop: pop_front (_clone, _copy, _with, _default, _copy_with _init), pop_back (_clone, _copy, _with, _default, _copy_with _init).
- Peek: peek_front (_mut), peek_back (_mut).
- Get: get (_prim, _mut, _mut_prim).
- Take: take_with, (_prim), take_default, (_prim), take_copy_with, (_prim), take_init, (_prim).
- Swap: swap_remove_with (_prim), swap_remove_default (_prim), swap_remove_copy (_prim), swap_remove_copy_with (_prim), swap_remove_init (_prim).
- Views: as_slices (_mut).
- Iteration: iter (_mut).
- Visitation: visit_each (_mut), visit_slices (_mut).
-
Fully initialized array of options (
option)- Constructors: new (_prim), from_array (_ring, _ring_prim, _linear, _clone, _copy), from_slice (_clone, _copy).
- Capacity: CAP (_PRIM), capacity (_prim), remaining_capacity (_prim), is_full.
- Logical range control: clear, truncate.
- Push: push_back (_copy), push_back_slice (_copy, _copy_exact). push_front (_copy), push_front_slice (_copy, _copy_exact).
- Pop: pop_front (_copy), pop_back (_copy).
- Peek: peek_front (_mut), peek_back (_mut).
- Get: get (_prim, _mut, _mut_prim).
- Swap: swap_remove (_prim, _copy, _copy_prim).
- Views: as_slices (_mut).
- Iteration: iter (_mut).
- Visitation: visit_each (_mut), visit_slices (_mut).
Implementations§
Source§impl<T, S> BufferRingStaticExample<T, S>
Common methods.
impl<T, S> BufferRingStaticExample<T, S>
Common methods.
Source§impl<T, const CAP: usize> BufferRingStaticExample<T, [T; CAP]>
Fully initialized ring array.
impl<T, const CAP: usize> BufferRingStaticExample<T, [T; CAP]>
Fully initialized ring array.
§Invariants
- All
CAPslots always contain a validT. lencontrols logical membership, not initialization.headis the physical start of the logical range.- The tail is derived as
(head + len) % CAP. - Dropping the ring drops all
CAPstored values.
§Consequences
- Pushing can overwrite inactive initialized slots.
- Popping by value needs
Copy,Clone, or a replacement value. - Shrinking
lendoes not drop elements immediately.
Sourcepub const CAP: NonValueU8<{ u8::MAX }>
pub const CAP: NonValueU8<{ u8::MAX }>
The fixed capacity of the ring as the index type.
Sourcepub const fn new(array: [T; CAP]) -> Self
pub const fn new(array: [T; CAP]) -> Self
Creates an empty ring from already initialized storage.
Sourcepub const fn new_init() -> Selfwhere
T: ConstInit,
pub const fn new_init() -> Selfwhere
T: ConstInit,
Creates an empty ring initialized with T::INIT.
Sourcepub const fn from_array_empty(array: [T; CAP]) -> Self
pub const fn from_array_empty(array: [T; CAP]) -> Self
Creates an empty ring from already initialized storage.
Sourcepub const fn from_array_full(array: [T; CAP]) -> Self
pub const fn from_array_full(array: [T; CAP]) -> Self
Creates a full ring from already initialized storage.
Sourcepub fn from_array_ring(
array: [T; CAP],
head: NonValueU8<{ u8::MAX }>,
len: NonValueU8<{ u8::MAX }>,
) -> Option<Self> ⓘ
pub fn from_array_ring( array: [T; CAP], head: NonValueU8<{ u8::MAX }>, len: NonValueU8<{ u8::MAX }>, ) -> Option<Self> ⓘ
Creates a ring from an array and explicit ring state.
Returns None if:
len > CAPhead >= CAPwhilelen > 0
Sourcepub fn from_array_ring_prim(array: [T; CAP], head: u8, len: u8) -> Option<Self> ⓘ
pub fn from_array_ring_prim(array: [T; CAP], head: u8, len: u8) -> Option<Self> ⓘ
Primitive-index variant of from_array_ring.
Sourcepub fn from_slice_clone(src: &[T], init: T) -> Option<Self> ⓘwhere
T: Clone,
pub fn from_slice_clone(src: &[T], init: T) -> Option<Self> ⓘwhere
T: Clone,
Creates a ring by cloning all elements from src,
after initializing the remaining capacity with init.
Sourcepub const fn from_slice_copy(src: &[T], init: T) -> Option<Self> ⓘwhere
T: Copy,
pub const fn from_slice_copy(src: &[T], init: T) -> Option<Self> ⓘwhere
T: Copy,
Creates a ring by copying all elements from src,
after initializing the remaining capacity with init.
Sourcepub const fn capacity(&self) -> NonValueU8<{ u8::MAX }>
pub const fn capacity(&self) -> NonValueU8<{ u8::MAX }>
Returns the fixed capacity of the ring.
Sourcepub const fn capacity_prim(&self) -> u8
pub const fn capacity_prim(&self) -> u8
Returns the fixed capacity of the ring.
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 clear(&mut self)
pub const fn clear(&mut self)
Sets the logical length to zero.
Does not drop elements. The array remains fully initialized.
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 ring.
Returns Err(value) if the ring 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 ring.
Returns Err(value) if the ring is full.
Sourcepub fn push_back_slice(&mut self, src: &[T]) -> usizewhere
T: Clone,
pub fn push_back_slice(&mut self, src: &[T]) -> usizewhere
T: Clone,
Appends as many cloned elements from src as fit at the back.
Elements keep their slice order.
Sourcepub const fn push_back_slice_copy(&mut self, src: &[T]) -> usizewhere
T: Copy,
pub const fn push_back_slice_copy(&mut self, src: &[T]) -> usizewhere
T: Copy,
Appends as many copied elements from src as fit at the back.
Elements keep their slice order.
Sourcepub const fn push_back_slice_copy_exact(
&mut self,
src: &[T],
) -> Result<(), usize> ⓘwhere
T: Copy,
pub const fn push_back_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 push_front(&mut self, value: T) -> Result<(), T> ⓘ
pub fn push_front(&mut self, value: T) -> Result<(), T> ⓘ
Prepends a value to the front of the ring.
Returns Err(value) if the ring is full.
Sourcepub const fn push_front_copy(&mut self, value: T) -> Result<(), T> ⓘwhere
T: Copy,
pub const fn push_front_copy(&mut self, value: T) -> Result<(), T> ⓘwhere
T: Copy,
Prepends a copy of value to the front of the ring.
Returns Err(value) if the ring is full.
Sourcepub fn push_front_slice(&mut self, src: &[T]) -> usizewhere
T: Clone,
pub fn push_front_slice(&mut self, src: &[T]) -> usizewhere
T: Clone,
Prepends as many cloned elements from src as fit at the front.
Elements keep their slice order. If the ring contains [10, 20],
then pushing [1, 2, 3] to the front makes the logical order
[1, 2, 3, 10, 20].
Sourcepub const fn push_front_slice_copy(&mut self, src: &[T]) -> usizewhere
T: Copy,
pub const fn push_front_slice_copy(&mut self, src: &[T]) -> usizewhere
T: Copy,
Prepends as many copied elements from src as fit at the front.
Elements keep their slice order. If the ring contains [10, 20],
then pushing [1, 2, 3] to the front makes the logical order
[1, 2, 3, 10, 20].
Sourcepub const fn push_front_slice_copy_exact(
&mut self,
src: &[T],
) -> Result<(), usize> ⓘwhere
T: Copy,
pub const fn push_front_slice_copy_exact(
&mut self,
src: &[T],
) -> Result<(), usize> ⓘwhere
T: Copy,
Prepends all copied elements from src, or none if insufficient capacity.
Returns Err(remaining_capacity) if not enough space is available.
Sourcepub fn pop_front_clone(&mut self) -> Option<T> ⓘwhere
T: Clone,
pub fn pop_front_clone(&mut self) -> Option<T> ⓘwhere
T: Clone,
Removes and returns a cloned value from the front of the ring.
Sourcepub const fn pop_front_copy(&mut self) -> Option<T> ⓘwhere
T: Copy,
pub const fn pop_front_copy(&mut self) -> Option<T> ⓘwhere
T: Copy,
Removes and returns a copied value from the front of the ring.
Sourcepub fn pop_front_with(&mut self, replacement: T) -> Option<T> ⓘ
pub fn pop_front_with(&mut self, replacement: T) -> Option<T> ⓘ
Removes and returns a value from the front,
replacing its storage slot with replacement.
Sourcepub fn pop_front_default(&mut self) -> Option<T> ⓘwhere
T: Default,
pub fn pop_front_default(&mut self) -> Option<T> ⓘwhere
T: Default,
Removes and returns a value from the front,
replacing its storage slot with T::default().
Sourcepub const fn pop_front_copy_with(&mut self, replacement: T) -> Option<T> ⓘwhere
T: Copy,
pub const fn pop_front_copy_with(&mut self, replacement: T) -> Option<T> ⓘwhere
T: Copy,
Removes and returns a copied value from the front,
replacing its storage slot with replacement.
Sourcepub const fn pop_front_init(&mut self) -> Option<T> ⓘ
pub const fn pop_front_init(&mut self) -> Option<T> ⓘ
Removes and returns a copied value from the front,
replacing its storage slot with T::INIT.
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 ring.
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 ring.
Sourcepub fn pop_back_with(&mut self, replacement: T) -> Option<T> ⓘ
pub fn pop_back_with(&mut self, replacement: T) -> Option<T> ⓘ
Removes and returns a value from the back,
replacing its storage slot with replacement.
Sourcepub fn pop_back_default(&mut self) -> Option<T> ⓘwhere
T: Default,
pub fn pop_back_default(&mut self) -> Option<T> ⓘwhere
T: Default,
Removes and returns a value from the back,
replacing its storage slot with T::default().
Sourcepub const fn pop_back_copy_with(&mut self, replacement: T) -> Option<T> ⓘwhere
T: Copy,
pub const fn pop_back_copy_with(&mut self, replacement: T) -> Option<T> ⓘwhere
T: Copy,
Removes and returns a copied value from the back,
replacing its storage slot with replacement.
Sourcepub const fn pop_back_init(&mut self) -> Option<T> ⓘ
pub const fn pop_back_init(&mut self) -> Option<T> ⓘ
Removes and returns a copied value from the back,
replacing its storage slot with T::INIT.
Sourcepub const fn peek_front(&self) -> Option<&T> ⓘ
pub const fn peek_front(&self) -> Option<&T> ⓘ
Returns a reference to the front element without removing it.
Sourcepub const fn peek_mut_front(&mut self) -> Option<&mut T> ⓘ
pub const fn peek_mut_front(&mut self) -> Option<&mut T> ⓘ
Returns an exclusive reference to the front element without removing it.
Sourcepub const fn peek_back(&self) -> Option<&T> ⓘ
pub const fn peek_back(&self) -> Option<&T> ⓘ
Returns a reference to the back 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 back 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 logical index.
Sourcepub const fn get_prim(&self, index: u8) -> Result<Option<&T>, InvalidValue> ⓘ
pub const fn get_prim(&self, index: u8) -> Result<Option<&T>, InvalidValue> ⓘ
Primitive-index variant of get.
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 logical index.
Sourcepub const fn get_mut_prim(
&mut self,
index: u8,
) -> Result<Option<&mut T>, InvalidValue> ⓘ
pub const fn get_mut_prim( &mut self, index: u8, ) -> Result<Option<&mut T>, InvalidValue> ⓘ
Primitive-index variant of get_mut.
Sourcepub fn take_with(
&mut self,
index: NonValueU8<{ u8::MAX }>,
replacement: T,
) -> Option<T> ⓘ
pub fn take_with( &mut self, index: NonValueU8<{ u8::MAX }>, replacement: T, ) -> Option<T> ⓘ
Takes the value at logical index, replacing it with replacement.
Does not change the logical length.
Sourcepub fn take_with_prim(
&mut self,
index: u8,
replacement: T,
) -> Result<Option<T>, InvalidValue> ⓘ
pub fn take_with_prim( &mut self, index: u8, replacement: T, ) -> Result<Option<T>, InvalidValue> ⓘ
Primitive-index variant of take_with.
Sourcepub fn take_default(&mut self, index: NonValueU8<{ u8::MAX }>) -> Option<T> ⓘwhere
T: Default,
pub fn take_default(&mut self, index: NonValueU8<{ u8::MAX }>) -> Option<T> ⓘwhere
T: Default,
Takes the value at logical index, replacing it with T::default().
Does not change the logical length.
Sourcepub fn take_default_prim(
&mut self,
index: u8,
) -> Result<Option<T>, InvalidValue> ⓘwhere
T: Default,
pub fn take_default_prim(
&mut self,
index: u8,
) -> Result<Option<T>, InvalidValue> ⓘwhere
T: Default,
Primitive-index variant of take_default.
Sourcepub const fn take_copy_with(
&mut self,
index: NonValueU8<{ u8::MAX }>,
replacement: T,
) -> Option<T> ⓘwhere
T: Copy,
pub const fn take_copy_with(
&mut self,
index: NonValueU8<{ u8::MAX }>,
replacement: T,
) -> Option<T> ⓘwhere
T: Copy,
Takes a copied value at logical index, replacing it with replacement.
Does not change the logical length.
Sourcepub const fn take_copy_with_prim(
&mut self,
index: u8,
replacement: T,
) -> Result<Option<T>, InvalidValue> ⓘwhere
T: Copy,
pub const fn take_copy_with_prim(
&mut self,
index: u8,
replacement: T,
) -> Result<Option<T>, InvalidValue> ⓘwhere
T: Copy,
Primitive-index variant of take_copy_with.
Sourcepub const fn take_init(&mut self, index: NonValueU8<{ u8::MAX }>) -> Option<T> ⓘwhere
T: ConstInit,
pub const fn take_init(&mut self, index: NonValueU8<{ u8::MAX }>) -> Option<T> ⓘwhere
T: ConstInit,
Takes the value at logical index, replacing it with T::INIT.
Does not change the logical length.
Sourcepub const fn take_init_prim(
&mut self,
index: u8,
) -> Result<Option<T>, InvalidValue> ⓘwhere
T: ConstInit,
pub const fn take_init_prim(
&mut self,
index: u8,
) -> Result<Option<T>, InvalidValue> ⓘwhere
T: ConstInit,
Primitive-index variant of take_init.
Sourcepub fn swap_remove_with(
&mut self,
index: NonValueU8<{ u8::MAX }>,
replacement: T,
) -> Option<T> ⓘ
pub fn swap_remove_with( &mut self, index: NonValueU8<{ u8::MAX }>, replacement: T, ) -> Option<T> ⓘ
Removes and returns the value at logical index,
filling the gap with the logical back element and replacing the
old back slot with replacement.
Decrements len. Does not preserve order.
Sourcepub fn swap_remove_with_prim(
&mut self,
index: u8,
replacement: T,
) -> Result<Option<T>, InvalidValue> ⓘ
pub fn swap_remove_with_prim( &mut self, index: u8, replacement: T, ) -> Result<Option<T>, InvalidValue> ⓘ
Primitive-index variant of swap_remove_with.
Sourcepub fn swap_remove_default(
&mut self,
index: NonValueU8<{ u8::MAX }>,
) -> Option<T> ⓘwhere
T: Default,
pub fn swap_remove_default(
&mut self,
index: NonValueU8<{ u8::MAX }>,
) -> Option<T> ⓘwhere
T: Default,
Removes and returns the value at logical index,
replacing the old back slot with T::default().
Decrements len. Does not preserve order.
Sourcepub fn swap_remove_default_prim(
&mut self,
index: u8,
) -> Result<Option<T>, InvalidValue> ⓘwhere
T: Default,
pub fn swap_remove_default_prim(
&mut self,
index: u8,
) -> Result<Option<T>, InvalidValue> ⓘwhere
T: Default,
Primitive-index variant of swap_remove_default.
Sourcepub const fn swap_remove_copy(
&mut self,
index: NonValueU8<{ u8::MAX }>,
) -> Option<T> ⓘwhere
T: Copy,
pub const fn swap_remove_copy(
&mut self,
index: NonValueU8<{ u8::MAX }>,
) -> Option<T> ⓘwhere
T: Copy,
Removes and returns a copied value at logical index,
filling the gap with the logical back element.
Decrements len. Does not preserve order.
The vacated physical back slot is left unchanged but outside the active logical range.
Sourcepub const fn swap_remove_copy_prim(
&mut self,
index: u8,
) -> Result<Option<T>, InvalidValue> ⓘwhere
T: Copy,
pub const fn swap_remove_copy_prim(
&mut self,
index: u8,
) -> Result<Option<T>, InvalidValue> ⓘwhere
T: Copy,
Primitive-index variant of swap_remove_copy.
Sourcepub const fn swap_remove_copy_with(
&mut self,
index: NonValueU8<{ u8::MAX }>,
replacement: T,
) -> Option<T> ⓘwhere
T: Copy,
pub const fn swap_remove_copy_with(
&mut self,
index: NonValueU8<{ u8::MAX }>,
replacement: T,
) -> Option<T> ⓘwhere
T: Copy,
Removes and returns a copied value at logical index,
filling the gap with the logical back element and replacing the
old back slot with replacement.
Decrements len. Does not preserve order.
Sourcepub const fn swap_remove_copy_with_prim(
&mut self,
index: u8,
replacement: T,
) -> Result<Option<T>, InvalidValue> ⓘwhere
T: Copy,
pub const fn swap_remove_copy_with_prim(
&mut self,
index: u8,
replacement: T,
) -> Result<Option<T>, InvalidValue> ⓘwhere
T: Copy,
Primitive-index variant of swap_remove_copy_with.
Sourcepub const fn swap_remove_init(
&mut self,
index: NonValueU8<{ u8::MAX }>,
) -> Option<T> ⓘ
pub const fn swap_remove_init( &mut self, index: NonValueU8<{ u8::MAX }>, ) -> Option<T> ⓘ
Removes and returns a copied value at logical index,
replacing the old back slot with T::INIT.
Decrements len. Does not preserve order.
Sourcepub const fn swap_remove_init_prim(
&mut self,
index: u8,
) -> Result<Option<T>, InvalidValue> ⓘ
pub const fn swap_remove_init_prim( &mut self, index: u8, ) -> Result<Option<T>, InvalidValue> ⓘ
Primitive-index variant of swap_remove_init.
Sourcepub fn as_slices(&self) -> (&[T], &[T]) ⓘ
pub fn as_slices(&self) -> (&[T], &[T]) ⓘ
Returns the active logical range as two slices.
The first slice starts at head. The second slice is non-empty
only when the active range wraps around the end of storage.
Sourcepub fn as_mut_slices(&mut self) -> (&mut [T], &mut [T]) ⓘ
pub fn as_mut_slices(&mut self) -> (&mut [T], &mut [T]) ⓘ
Returns the active logical range as two mutable slices.
The first slice starts at head. The second slice is non-empty
only when the active range wraps around the end of storage.
Sourcepub fn iter(&self) -> impl Iterator<Item = &T>
pub fn iter(&self) -> impl Iterator<Item = &T>
Iterates over the active elements in logical order.
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 active elements in logical order.
Sourcepub fn visit_each<F>(&self, f: F)
pub fn visit_each<F>(&self, f: F)
Visits each active 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 active element mutably without exposing borrow identity.
Sourcepub fn visit_slices<F, R>(&self, f: F) -> R
pub fn visit_slices<F, R>(&self, f: F) -> R
Visits the active logical range as two shared slices.
Sourcepub fn visit_mut_slices<F, R>(&mut self, f: F) -> R
pub fn visit_mut_slices<F, R>(&mut self, f: F) -> R
Visits the active logical range as two exclusive slices.
Source§impl<T, const CAP: usize> BufferRingStaticExample<T, [Option<T>; CAP]>
Ring buffer backed by [Option<T>; CAP].
impl<T, const CAP: usize> BufferRingStaticExample<T, [Option<T>; CAP]>
Ring buffer backed by [Option<T>; CAP].
§Invariants
len <= CAP.- If
len == 0,head == 0. - If
len > 0,head < CAP. - The occupied logical range
0 .. lenmaps through(head + logical_index) % CAP. - Occupied physical slots are
Some(T). - Unoccupied physical slots are
None.
§Notes
Option<T>is used to control occupancy and dropping, not sparsity.tailis derived as(head + len) % CAP.
Sourcepub const CAP: NonValueU8<{ u8::MAX }>
pub const CAP: NonValueU8<{ u8::MAX }>
The fixed capacity of the ring as the index type.
Sourcepub fn from_array_ring(
array: [Option<T>; CAP],
head: NonValueU8<{ u8::MAX }>,
len: NonValueU8<{ u8::MAX }>,
) -> Option<Self> ⓘ
pub fn from_array_ring( array: [Option<T>; CAP], head: NonValueU8<{ u8::MAX }>, len: NonValueU8<{ u8::MAX }>, ) -> Option<Self> ⓘ
Creates a ring from an array of options and explicit ring state.
Returns None if the occupied slots do not match head and len.
Sourcepub fn from_array_ring_prim(
array: [Option<T>; CAP],
head: u8,
len: u8,
) -> Option<Self> ⓘ
pub fn from_array_ring_prim( array: [Option<T>; CAP], head: u8, len: u8, ) -> Option<Self> ⓘ
Primitive-index variant of from_array_ring.
Returns None if the occupied slots do not match head and len,
or if any of the given primitive values are invalid.
Sourcepub fn from_array_linear(array: [Option<T>; CAP]) -> Option<Self> ⓘ
pub fn from_array_linear(array: [Option<T>; CAP]) -> Option<Self> ⓘ
Creates a ring from an array of options with a linear prefix layout.
The ring head is 0, and the logical length is inferred as the
index of the first None.
Returns None if a Some appears after the first None.
Sourcepub fn from_slice_clone(src: &[T]) -> Option<Self> ⓘwhere
T: Clone,
pub fn from_slice_clone(src: &[T]) -> Option<Self> ⓘwhere
T: Clone,
Creates a ring by cloning all elements from src.
Sourcepub const fn from_slice_copy(src: &[T]) -> Option<Self> ⓘwhere
T: Copy,
pub const fn from_slice_copy(src: &[T]) -> Option<Self> ⓘwhere
T: Copy,
Creates a ring by copying all elements from src.
Sourcepub fn from_array_clone<const N: usize>(src: [T; N]) -> Option<Self> ⓘwhere
T: Clone,
pub fn from_array_clone<const N: usize>(src: [T; N]) -> Option<Self> ⓘwhere
T: Clone,
Creates a ring by cloning all elements from an array.
Sourcepub const fn from_array_copy<const N: usize>(src: [T; N]) -> Option<Self> ⓘwhere
T: Copy,
pub const fn from_array_copy<const N: usize>(src: [T; N]) -> Option<Self> ⓘwhere
T: Copy,
Creates a ring by copying all elements from an array.
Sourcepub const fn capacity(&self) -> NonValueU8<{ u8::MAX }>
pub const fn capacity(&self) -> NonValueU8<{ u8::MAX }>
Returns the fixed capacity of the ring.
Sourcepub const fn capacity_prim(&self) -> u8
pub const fn capacity_prim(&self) -> u8
Returns the fixed capacity of the ring.
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 fn truncate(&mut self, new_len: NonValueU8<{ u8::MAX }>)
pub fn truncate(&mut self, new_len: NonValueU8<{ u8::MAX }>)
Truncates the ring to new_len, dropping elements from the back.
If new_len >= len, this is a no-op.
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 ring.
Returns Err(value) if the ring 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 ring.
Returns Err(value) if the ring is full.
Sourcepub fn push_back_slice(&mut self, src: &[T]) -> usizewhere
T: Clone,
pub fn push_back_slice(&mut self, src: &[T]) -> usizewhere
T: Clone,
Appends as many elements cloned from src as fit at the back of the ring.
Elements keep their slice order.
After pushing [a, b, c], c becomes the logical back element.
Sourcepub const fn push_back_slice_copy(&mut self, src: &[T]) -> usizewhere
T: Copy,
pub const fn push_back_slice_copy(&mut self, src: &[T]) -> usizewhere
T: Copy,
Appends as many elements copied from src as fit at the back of the ring.
Elements keep their slice order.
After pushing [a, b, c], c becomes the logical back element.
Sourcepub const fn push_back_slice_copy_exact(
&mut self,
src: &[T],
) -> Result<(), usize> ⓘwhere
T: Copy,
pub const fn push_back_slice_copy_exact(
&mut self,
src: &[T],
) -> Result<(), usize> ⓘwhere
T: Copy,
Appends all copied from src at the back of the ring,
or none if insufficient capacity.
Returns Err(remaining_capacity) if not enough space is available.
Elements keep their slice order.
After pushing [a, b, c], c becomes the logical back element.
Sourcepub fn push_front(&mut self, value: T) -> Result<(), T> ⓘ
pub fn push_front(&mut self, value: T) -> Result<(), T> ⓘ
Prepends a value to the front of the ring.
Returns Err(value) if the ring is full.
Sourcepub const fn push_front_copy(&mut self, value: T) -> Result<(), T> ⓘwhere
T: Copy,
pub const fn push_front_copy(&mut self, value: T) -> Result<(), T> ⓘwhere
T: Copy,
Prepends a copy of value to the front of the ring.
Returns Err(value) if the ring is full.
Sourcepub fn push_front_slice(&mut self, src: &[T]) -> usizewhere
T: Clone,
pub fn push_front_slice(&mut self, src: &[T]) -> usizewhere
T: Clone,
Prepends as many elements cloned from src as fit.
Elements keep their slice order. If the ring contains [10, 20],
then pushing [1, 2, 3] to the front makes the logical order
[1, 2, 3, 10, 20].
Returns the number of elements prepended.
Sourcepub const fn push_front_slice_copy(&mut self, src: &[T]) -> usizewhere
T: Copy,
pub const fn push_front_slice_copy(&mut self, src: &[T]) -> usizewhere
T: Copy,
Prepends as many copied elements from src as fit.
Elements keep their slice order. If the ring contains [10, 20],
then pushing [1, 2, 3] to the front makes the logical order
[1, 2, 3, 10, 20].
Returns the number of elements prepended.
Sourcepub const fn push_front_slice_copy_exact(
&mut self,
src: &[T],
) -> Result<(), usize> ⓘwhere
T: Copy,
pub const fn push_front_slice_copy_exact(
&mut self,
src: &[T],
) -> Result<(), usize> ⓘwhere
T: Copy,
Prepends all copied elements from src, or none if insufficient capacity.
Elements keep their slice order. Returns Err(remaining_capacity) if not
enough space is available.
Sourcepub fn pop_front(&mut self) -> Option<T> ⓘ
pub fn pop_front(&mut self) -> Option<T> ⓘ
Removes and returns a value from the front of the ring.
Sourcepub const fn pop_front_copy(&mut self) -> Option<T> ⓘwhere
T: Copy,
pub const fn pop_front_copy(&mut self) -> Option<T> ⓘwhere
T: Copy,
Removes and returns a copy from the front of the ring.
Sourcepub fn pop_back(&mut self) -> Option<T> ⓘ
pub fn pop_back(&mut self) -> Option<T> ⓘ
Removes and returns a value from the back of the ring.
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 copy from the back of the ring.
Sourcepub const fn peek_front(&self) -> Option<&T> ⓘ
pub const fn peek_front(&self) -> Option<&T> ⓘ
Returns a reference to the front element without removing it.
Sourcepub fn peek_mut_front(&mut self) -> Option<&mut T> ⓘ
pub fn peek_mut_front(&mut self) -> Option<&mut T> ⓘ
Returns an exclusive reference to the front element without removing it.
Sourcepub const fn peek_back(&self) -> Option<&T> ⓘ
pub const fn peek_back(&self) -> Option<&T> ⓘ
Returns a reference to the back element without removing it.
Sourcepub fn peek_mut_back(&mut self) -> Option<&mut T> ⓘ
pub fn peek_mut_back(&mut self) -> Option<&mut T> ⓘ
Returns an exclusive reference to the back 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 logical index.
Sourcepub const fn get_prim(&self, index: u8) -> Result<Option<&T>, InvalidValue> ⓘ
pub const fn get_prim(&self, index: u8) -> Result<Option<&T>, InvalidValue> ⓘ
Primitive-index variant of get.
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 logical index.
Sourcepub const fn get_mut_prim(
&mut self,
index: u8,
) -> Result<Option<&mut T>, InvalidValue> ⓘ
pub const fn get_mut_prim( &mut self, index: u8, ) -> Result<Option<&mut T>, InvalidValue> ⓘ
Primitive-index variant of get_mut.
Sourcepub fn swap_remove(&mut self, index: NonValueU8<{ u8::MAX }>) -> Option<T> ⓘ
pub fn swap_remove(&mut self, index: NonValueU8<{ u8::MAX }>) -> Option<T> ⓘ
Removes and returns the value at logical index,
filling the gap with the logical back element.
Decrements len. Does not preserve order.
Sourcepub fn swap_remove_prim(&mut self, index: u8) -> Result<Option<T>, InvalidValue> ⓘ
pub fn swap_remove_prim(&mut self, index: u8) -> Result<Option<T>, InvalidValue> ⓘ
Primitive-index variant of swap_remove.
Sourcepub const fn swap_remove_copy(
&mut self,
index: NonValueU8<{ u8::MAX }>,
) -> Option<T> ⓘwhere
T: Copy,
pub const fn swap_remove_copy(
&mut self,
index: NonValueU8<{ u8::MAX }>,
) -> Option<T> ⓘwhere
T: Copy,
Removes and returns a copy of the value at logical index,
filling the gap with the logical back element.
Decrements len. Does not preserve order.
Sourcepub fn swap_remove_copy_prim(
&mut self,
index: u8,
) -> Result<Option<T>, InvalidValue> ⓘwhere
T: Copy,
pub fn swap_remove_copy_prim(
&mut self,
index: u8,
) -> Result<Option<T>, InvalidValue> ⓘwhere
T: Copy,
Primitive-index variant of swap_remove_copy.
Sourcepub fn as_slices(&self) -> (&[Option<T>], &[Option<T>]) ⓘ
pub fn as_slices(&self) -> (&[Option<T>], &[Option<T>]) ⓘ
Returns the active logical range as two option slices.
The first slice starts at head. The second slice is non-empty
only when the active range wraps around the end of storage.
Sourcepub fn as_mut_slices(&mut self) -> (&mut [Option<T>], &mut [Option<T>]) ⓘ
pub fn as_mut_slices(&mut self) -> (&mut [Option<T>], &mut [Option<T>]) ⓘ
Returns the active logical range as two mutable option slices.
The first slice starts at head. The second slice is non-empty
only when the active range wraps around the end of storage.
Sourcepub fn iter(&self) -> impl Iterator<Item = &T>
pub fn iter(&self) -> impl Iterator<Item = &T>
Iterates over the initialized elements in logical order.
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 in logical order.
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_slices<F, R>(&self, f: F) -> R
pub fn visit_slices<F, R>(&self, f: F) -> R
Visits the active logical range as two shared option slices.
Sourcepub fn visit_mut_slices<F, R>(&mut self, f: F) -> R
pub fn visit_mut_slices<F, R>(&mut self, f: F) -> R
Visits the active logical range as two exclusive option slices.
Trait Implementations§
Source§impl<T: Clone, S: Clone> Clone for BufferRingStaticExample<T, S>
impl<T: Clone, S: Clone> Clone for BufferRingStaticExample<T, S>
Source§fn clone(&self) -> BufferRingStaticExample<T, S>
fn clone(&self) -> BufferRingStaticExample<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<T: Copy, S: Copy> Copy for BufferRingStaticExample<T, S>
impl<T: Eq, S: Eq> Eq for BufferRingStaticExample<T, S>
Source§impl<T: Ord, S: Ord> Ord for BufferRingStaticExample<T, S>
impl<T: Ord, S: Ord> Ord for BufferRingStaticExample<T, S>
Source§fn cmp(&self, other: &BufferRingStaticExample<T, S>) -> Ordering
fn cmp(&self, other: &BufferRingStaticExample<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<T: PartialEq, S: PartialEq> PartialEq for BufferRingStaticExample<T, S>
impl<T: PartialEq, S: PartialEq> PartialEq for BufferRingStaticExample<T, S>
Source§fn eq(&self, other: &BufferRingStaticExample<T, S>) -> bool
fn eq(&self, other: &BufferRingStaticExample<T, S>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T: PartialOrd, S: PartialOrd> PartialOrd for BufferRingStaticExample<T, S>
impl<T: PartialOrd, S: PartialOrd> PartialOrd for BufferRingStaticExample<T, S>
impl<T, S> StructuralPartialEq for BufferRingStaticExample<T, S>
Auto Trait Implementations§
impl<T, S> Freeze for BufferRingStaticExample<T, S>where
S: Freeze,
impl<T, S> RefUnwindSafe for BufferRingStaticExample<T, S>where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S> Send for BufferRingStaticExample<T, S>
impl<T, S> Sync for BufferRingStaticExample<T, S>
impl<T, S> Unpin for BufferRingStaticExample<T, S>
impl<T, S> UnsafeUnpin for BufferRingStaticExample<T, S>where
S: UnsafeUnpin,
impl<T, S> UnwindSafe for BufferRingStaticExample<T, S>where
S: UnwindSafe,
T: UnwindSafe,
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
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.