pub struct BufferLinearStaticExample<T, S> { /* private fields */ }Expand description
✨ 🗃️
A static linear buffer over contiguous storage, made with buffer_linear!.
📍 data/layout/buffer::BufferLinearStaticExample
📦 size_of::<BufferLinearStaticExample<(), [(); 8]>>() == 1 bytes / 8 bits
⚗️Option<T> 🟰 T
📦 size_of::<BufferLinearStaticExample<u8, [u8; 8]>>() == 9 bytes / 72 bits
⚗️Option<T> 🟰 T
📦 size_of::<BufferLinearStaticExample<i32, [i32; 8]>>() == 36 bytes / 288 bits
⚗️Option<T> 🟰 T
📦 size_of::<BufferLinearStaticExample<char, &[i32]>>() == 12 bytes / 96 bits #️⃣ #[cfg(target_pointer_width = “32”)]
⚗️Option<T> 🟰 T
📦 size_of::<BufferLinearStaticExample<char, &[i32]>>() == 24 bytes / 192 bits #️⃣ #[cfg(target_pointer_width = “64”)]
⚗️Option<T> 🟰 T
§Methods
- common methods
- Fully initialized array
(
array)- Constructors: new (_init), from_array (from_array_clamped, _prim), from_slice (_clone, _copy, _move_default).
- Capacity: CAP (_PRIM), capacity (_prim), remaining_capacity (_prim), is_full.
- Logical range control: clear (_copy), truncate, (_copy, _prim, _prim_copy).
- Push: push_back (_copy), push_slice (_copy, _copy_exact).
- Pop: pop_back_clone, pop_back_copy.
- Peek: peek_back (_mut).
- Get: get (_mut).
- Take: take_default, take_init, take_with (_copy).
- Views: as_slice (_mut),
- Iteration: iter (_mut).
- Visitation: visit_each (_mut), visit_slice (_mut).
- Partially initialized array
(
uninit)⚠- Constructors: new, from_array (_exact _unchecked⚠), from_slice (_clone, _copy, _move_default, _move_init).
- Capacity: CAP (_PRIM), capacity (_prim), remaining_capacity (_prim), is_full.
- Logical range control: clear, drop_back, truncate, (_prim).
- Push: push_back, push_slice (_copy, _copy_exact).
- Pop: pop_back.
- Peek: peek_back (_mut).
- Get: get (_mut).
- Views: as_slice (_mut),
- Iteration: iter (_mut).
- Visitation: visit_each (_mut), visit_slice (_mut).
- Fully initialized array of options
(
option)- Constructors: new, from_array (_clone, _copy, _unchecked⚠, _linear, _prefix), from_slice (_clone, _copy, _move_default, _move_init).
- Capacity: CAP (_PRIM), capacity (_prim), remaining_capacity (_prim), is_full.
- Logical range control: clear, truncate.
- Push: push_back (_copy), push_slice (_copy, _copy_exact).
- Pop: pop_back.
- Peek: peek_back (_mut).
- Get: get (_mut).
- Swap: swap_remove (_prim, _copy, _copy_prim).
- Views: as_slice (_mut),
- Iteration: iter (_mut).
- Visitation: visit_each (_mut), visit_slice (_mut).
Implementations§
Source§impl<T, S> BufferLinearStaticExample<T, S>
Common methods.
impl<T, S> BufferLinearStaticExample<T, S>
Common methods.
Source§impl<T, const CAP: usize> BufferLinearStaticExample<T, [T; CAP]>
Fully initialized linear array.
impl<T, const CAP: usize> BufferLinearStaticExample<T, [T; CAP]>
Fully initialized linear array.
§Invariants
- All CAP slots always contain a valid
T. lencontrols logical membership, not initialization.- Dropping the array drops all
CAPelements.
§Consequences
- Moving out
Trequires immediately installing another validT. - Popping by value therefore requires
Copy,Clone, or a replacement value. - Shrinking
lendoes not affect drop behavior.
Sourcepub const CAP: NonValueU8<{ u8::MAX }>
pub const CAP: NonValueU8<{ u8::MAX }>
The fixed capacity of the buffer as the index type.
Sourcepub const fn new(array: [T; CAP]) -> Self
pub const fn new(array: [T; CAP]) -> Self
Creates a buffer from an already initialized array, with logical length 0.
Sourcepub const fn new_init() -> Selfwhere
T: ConstInit,
pub const fn new_init() -> Selfwhere
T: ConstInit,
Creates a new fully initialized buffer with logical length 0.
Sourcepub const fn from_array_clamped(
array: [T; CAP],
max_len: NonValueU8<{ u8::MAX }>,
) -> Self
pub const fn from_array_clamped( array: [T; CAP], max_len: NonValueU8<{ u8::MAX }>, ) -> Self
Creates a buffer from an already initialized array,
limiting the logical length to max_len.
Sourcepub const fn from_array_clamped_prim(array: [T; CAP], max_len: u8) -> Self
pub const fn from_array_clamped_prim(array: [T; CAP], max_len: u8) -> Self
Primitive-index variant of from_array_clamped.
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 new buffer by cloning all the possible elements from src,
after initializing the capacity with the init value.
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 new buffer by copying all the possible elements from src,
after initializing the capacity with the init value.
Sourcepub fn from_slice_move_default(src: &mut [T]) -> Option<Self> ⓘwhere
T: Default,
pub fn from_slice_move_default(src: &mut [T]) -> Option<Self> ⓘwhere
T: Default,
Creates a new buffer by moving all the possible elements from src,
and replacing them with the default value,
after initializing the capacity with the default value.
Sourcepub const fn capacity(&self) -> NonValueU8<{ u8::MAX }>
pub const fn capacity(&self) -> NonValueU8<{ u8::MAX }>
Returns the fixed capacity of the buffer.
Sourcepub const fn capacity_prim(&self) -> u8
pub const fn capacity_prim(&self) -> u8
Returns the fixed capacity of the buffer.
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 cloned elements 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 returns the number appended before running out of space.
Sourcepub const fn pop_back(&mut self) -> Option<T> ⓘwhere
T: ConstInit,
pub const fn pop_back(&mut self) -> Option<T> ⓘwhere
T: ConstInit,
Removes and returns the value at the back,
replacing its storage slot with T::INIT.
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 the value at the back,
replacing its storage slot with replacement.
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 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 index, replacing it with T::default().
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 index, replacing it with T::INIT.
Sourcepub fn take_with(
&mut self,
index: NonValueU8<{ u8::MAX }>,
other: T,
) -> Option<T> ⓘ
pub fn take_with( &mut self, index: NonValueU8<{ u8::MAX }>, other: T, ) -> Option<T> ⓘ
Takes the value at index, replacing it with other.
Sourcepub const fn take_with_copy(
&mut self,
index: NonValueU8<{ u8::MAX }>,
other: T,
) -> Option<T> ⓘwhere
T: Copy,
pub const fn take_with_copy(
&mut self,
index: NonValueU8<{ u8::MAX }>,
other: T,
) -> Option<T> ⓘwhere
T: Copy,
Takes the value at index, replacing it with a copy of other.
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 an exclusive 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<T, const CAP: usize> BufferLinearStaticExample<T, [MaybeUninit<T>; CAP]>
Partially initialized array.
impl<T, const CAP: usize> BufferLinearStaticExample<T, [MaybeUninit<T>; CAP]>
Partially initialized array.
§Invariants
- Only slots
0 .. lenare initialized - Slots
len .. CAPare uninitialized and must never be dropped asT - Drop behavior depends on
len
Consequences
- pop_back can safely move out
T - Real drop operations are meaningful
lencontrols both logical membership and initialization
Sourcepub const CAP: NonValueU8<{ u8::MAX }>
Available on crate feature unsafe_array only.
pub const CAP: NonValueU8<{ u8::MAX }>
unsafe_array only.The fixed capacity of the buffer as the index type.
Sourcepub const CAP_PRIM: u8
Available on crate feature unsafe_array only.
pub const CAP_PRIM: u8
unsafe_array only.The fixed capacity of the buffer as the primitive type.
Sourcepub const fn new() -> Self
Available on crate feature unsafe_array only.
pub const fn new() -> Self
unsafe_array only.Creates an empty buffer with uninitialized storage.
Sourcepub fn from_array_exact<const N: usize>(src: [T; N]) -> Self
Available on crate feature unsafe_array only.
pub fn from_array_exact<const N: usize>(src: [T; N]) -> Self
unsafe_array only.Creates a buffer by moving all elements from an array.
Initializes exactly N elements.
§Panics
Panics if N > CAP.
Sourcepub const unsafe fn from_array_unchecked(
storage: [MaybeUninit<T>; CAP],
len: NonValueU8<{ u8::MAX }>,
) -> Self
Available on crate feature unsafe_array only.
pub const unsafe fn from_array_unchecked( storage: [MaybeUninit<T>; CAP], len: NonValueU8<{ u8::MAX }>, ) -> Self
unsafe_array only.Sourcepub fn from_slice_clone(src: &[T]) -> Option<Self> ⓘwhere
T: Clone,
Available on crate feature unsafe_array only.
pub fn from_slice_clone(src: &[T]) -> Option<Self> ⓘwhere
T: Clone,
unsafe_array only.Creates a new buffer by cloning all the possible elements from src.
Sourcepub const fn from_slice_copy(src: &[T]) -> Option<Self> ⓘwhere
T: Copy,
Available on crate feature unsafe_array only.
pub const fn from_slice_copy(src: &[T]) -> Option<Self> ⓘwhere
T: Copy,
unsafe_array only.Creates a new buffer by copying all the possible elements from src.
Sourcepub fn from_slice_move_default(src: &mut [T]) -> Option<Self> ⓘwhere
T: Default,
Available on crate feature unsafe_array only.
pub fn from_slice_move_default(src: &mut [T]) -> Option<Self> ⓘwhere
T: Default,
unsafe_array only.Creates a new buffer by moving all the possible elements from src,
and replacing them with the default value.
Sourcepub const fn from_slice_move_init(src: &mut [T]) -> Option<Self> ⓘwhere
T: ConstInit,
Available on crate feature unsafe_array only.
pub const fn from_slice_move_init(src: &mut [T]) -> Option<Self> ⓘwhere
T: ConstInit,
unsafe_array only.Creates a new buffer by moving all the possible elements from src,
and replacing them with the initializing value.
Sourcepub const fn capacity(&self) -> NonValueU8<{ u8::MAX }>
Available on crate feature unsafe_array only.
pub const fn capacity(&self) -> NonValueU8<{ u8::MAX }>
unsafe_array only.Returns the fixed capacity of the buffer.
Sourcepub const fn capacity_prim(&self) -> u8
Available on crate feature unsafe_array only.
pub const fn capacity_prim(&self) -> u8
unsafe_array only.Returns the fixed capacity of the buffer.
Sourcepub const fn remaining_capacity(&self) -> NonValueU8<{ u8::MAX }>
Available on crate feature unsafe_array only.
pub const fn remaining_capacity(&self) -> NonValueU8<{ u8::MAX }>
unsafe_array only.Returns the number of additional elements that fit within the current capacity.
Sourcepub const fn remaining_capacity_prim(&self) -> u8
Available on crate feature unsafe_array only.
pub const fn remaining_capacity_prim(&self) -> u8
unsafe_array only.Returns the number of additional elements that fit within the current capacity.
Sourcepub const fn is_full(&self) -> bool
Available on crate feature unsafe_array only.
pub const fn is_full(&self) -> bool
unsafe_array only.Returns true if the buffer has reached its capacity.
Sourcepub fn clear(&mut self)
Available on crate feature unsafe_array only.
pub fn clear(&mut self)
unsafe_array only.Drops all initialized elements and resets the buffer.
Sourcepub const fn clear_copy(&mut self)where
T: Copy,
Available on crate feature unsafe_array only.
pub const fn clear_copy(&mut self)where
T: Copy,
unsafe_array only.Resets the buffer of Copy elements.
Sourcepub fn drop_back(&mut self) -> bool
Available on crate feature unsafe_array only.
pub fn drop_back(&mut self) -> bool
unsafe_array only.Drops the last element without returning it.
Sourcepub fn truncate(&mut self, new_len: NonValueU8<{ u8::MAX }>)
Available on crate feature unsafe_array only.
pub fn truncate(&mut self, new_len: NonValueU8<{ u8::MAX }>)
unsafe_array only.Sets the length to min(new_len, len), dropping the truncated elements.
If new_len >= len, this is a no-op.
Sourcepub const fn truncate_copy(&mut self, new_len: NonValueU8<{ u8::MAX }>)where
T: Copy,
Available on crate feature unsafe_array only.
pub const fn truncate_copy(&mut self, new_len: NonValueU8<{ u8::MAX }>)where
T: Copy,
unsafe_array only.Shortens the buffer of Copy elements.
If new_len >= len, this is a no-op.
Sourcepub fn truncate_prim(&mut self, new_len: u8) -> Result<(), InvalidValue> ⓘ
Available on crate feature unsafe_array only.
pub fn truncate_prim(&mut self, new_len: u8) -> Result<(), InvalidValue> ⓘ
unsafe_array only.Primitive-index variant of truncate,
Sourcepub const fn truncate_prim_copy(
&mut self,
new_len: u8,
) -> Result<(), InvalidValue> ⓘwhere
T: Copy,
Available on crate feature unsafe_array only.
pub const fn truncate_prim_copy(
&mut self,
new_len: u8,
) -> Result<(), InvalidValue> ⓘwhere
T: Copy,
unsafe_array only.Primitive-index variant of truncate_copy,
Sourcepub const fn push_back(&mut self, value: T) -> Result<(), T> ⓘ
Available on crate feature unsafe_array only.
pub const fn push_back(&mut self, value: T) -> Result<(), T> ⓘ
unsafe_array only.Appends a 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,
Available on crate feature unsafe_array only.
pub fn push_slice(&mut self, src: &[T]) -> usizewhere
T: Clone,
unsafe_array only.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,
Available on crate feature unsafe_array only.
pub const fn push_slice_copy(&mut self, src: &[T]) -> usizewhere
T: Copy,
unsafe_array only.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,
Available on crate feature unsafe_array only.
pub const fn push_slice_copy_exact(&mut self, src: &[T]) -> Result<(), usize> ⓘwhere
T: Copy,
unsafe_array only.Appends all copied elements from src, or none if insufficient capacity.
Returns Err(remaining_capacity) if not enough space is available.
Sourcepub const fn pop_back(&mut self) -> Option<T> ⓘ
Available on crate feature unsafe_array only.
pub const fn pop_back(&mut self) -> Option<T> ⓘ
unsafe_array only.Removes and returns the last element.
This moves the value out without requiring T: Copy or T: Clone.
Sourcepub const fn peek_back(&self) -> Option<&T> ⓘ
Available on crate feature unsafe_array only.
pub const fn peek_back(&self) -> Option<&T> ⓘ
unsafe_array only.Returns a reference to the last element without removing it.
Sourcepub const fn peek_mut_back(&mut self) -> Option<&mut T> ⓘ
Available on crate feature unsafe_array only.
pub const fn peek_mut_back(&mut self) -> Option<&mut T> ⓘ
unsafe_array only.Returns an exclusive reference to the last element without removing it.
Sourcepub const fn get(&self, index: NonValueU8<{ u8::MAX }>) -> Option<&T> ⓘ
Available on crate feature unsafe_array only.
pub const fn get(&self, index: NonValueU8<{ u8::MAX }>) -> Option<&T> ⓘ
unsafe_array only.Returns a reference to the element at index, if within bounds.
Sourcepub const fn get_mut(
&mut self,
index: NonValueU8<{ u8::MAX }>,
) -> Option<&mut T> ⓘ
Available on crate feature unsafe_array only.
pub const fn get_mut( &mut self, index: NonValueU8<{ u8::MAX }>, ) -> Option<&mut T> ⓘ
unsafe_array only.Returns an exclusive reference to the element at index, if within bounds.
Sourcepub fn take_default(&mut self, index: NonValueU8<{ u8::MAX }>) -> Option<T> ⓘwhere
T: Default,
Available on crate feature unsafe_array only.
pub fn take_default(&mut self, index: NonValueU8<{ u8::MAX }>) -> Option<T> ⓘwhere
T: Default,
unsafe_array only.Takes the value at index, replacing it with T::default().
Sourcepub const fn take_init(&mut self, index: NonValueU8<{ u8::MAX }>) -> Option<T> ⓘwhere
T: ConstInit,
Available on crate feature unsafe_array only.
pub const fn take_init(&mut self, index: NonValueU8<{ u8::MAX }>) -> Option<T> ⓘwhere
T: ConstInit,
unsafe_array only.Takes the value at index, replacing it with T::INIT.
Sourcepub fn take_with(
&mut self,
index: NonValueU8<{ u8::MAX }>,
value: T,
) -> Option<T> ⓘ
Available on crate feature unsafe_array only.
pub fn take_with( &mut self, index: NonValueU8<{ u8::MAX }>, value: T, ) -> Option<T> ⓘ
unsafe_array only.Takes the value at index, replacing it with value.
Sourcepub const fn as_slice(&self) -> &[T] ⓘ
Available on crate feature unsafe_array only.
pub const fn as_slice(&self) -> &[T] ⓘ
unsafe_array only.Returns the active logical range as a slice.
Sourcepub const fn as_mut_slice(&mut self) -> &mut [T] ⓘ
Available on crate feature unsafe_array only.
pub const fn as_mut_slice(&mut self) -> &mut [T] ⓘ
unsafe_array only.Returns the active logical range as a mutable slice.
Sourcepub fn iter(&self) -> impl Iterator<Item = &T>
Available on crate feature unsafe_array only.
pub fn iter(&self) -> impl Iterator<Item = &T>
unsafe_array only.Iterates over the initialized elements.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>
Available on crate feature unsafe_array only.
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>
unsafe_array only.Iterates mutably over the initialized elements.
Sourcepub fn visit_each<F>(&self, f: F)
Available on crate feature unsafe_array only.
pub fn visit_each<F>(&self, f: F)
unsafe_array only.Visits each initialized element without exposing borrow identity.
Sourcepub fn visit_each_mut<F>(&mut self, f: F)
Available on crate feature unsafe_array only.
pub fn visit_each_mut<F>(&mut self, f: F)
unsafe_array only.Visits each initialized element mutably without exposing borrow identity.
Sourcepub fn visit_slice<F, R>(&self, f: F) -> R
Available on crate feature unsafe_array only.
pub fn visit_slice<F, R>(&self, f: F) -> R
unsafe_array only.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
Available on crate feature unsafe_array only.
pub fn visit_mut_slice<F, R>(&mut self, f: F) -> R
unsafe_array only.Visits the active logical range as an exclusive slice of Some(T),
without exposing borrow identity.
Source§impl<T, const CAP: usize> BufferLinearStaticExample<T, [Option<T>; CAP]>
Fully initialized array using Option<T> as a drop boundary.
impl<T, const CAP: usize> BufferLinearStaticExample<T, [Option<T>; CAP]>
Fully initialized array using Option<T> as a drop boundary.
§Invariants
- Slots
0 .. lenareSome - Slots
len .. CAPare logically outside the buffer - No holes are permitted in the active logical range.
§Notes
Option<T>is used to control initialization and dropping, not sparsitylenis the number of elements- Methods never access storage past
len
Sourcepub const CAP: NonValueU8<{ u8::MAX }>
pub const CAP: NonValueU8<{ u8::MAX }>
The fixed capacity of the buffer as the index type.
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a buffer from a fully initialized array with logical length 0.
Sourcepub fn from_array_clone<const N: usize>(src: [T; N]) -> Selfwhere
T: Clone,
pub fn from_array_clone<const N: usize>(src: [T; N]) -> Selfwhere
T: Clone,
Sourcepub const fn from_array_copy<const N: usize>(src: [T; N]) -> Selfwhere
T: Copy,
pub const fn from_array_copy<const N: usize>(src: [T; N]) -> Selfwhere
T: Copy,
Sourcepub const unsafe fn from_array_unchecked(
array: [Option<T>; CAP],
len: NonValueU8<{ u8::MAX }>,
) -> Self
Available on crate feature unsafe_array only.
pub const unsafe fn from_array_unchecked( array: [Option<T>; CAP], len: NonValueU8<{ u8::MAX }>, ) -> Self
unsafe_array only.Sourcepub fn from_array_linear(array: [Option<T>; CAP]) -> Option<Self> ⓘ
pub fn from_array_linear(array: [Option<T>; CAP]) -> Option<Self> ⓘ
Creates a buffer from an array of options, validating the linear invariant.
Returns None if:
- a
Noneappears before aSome - any element after the active logical range is
Some
Sourcepub fn from_array_prefix(array: [Option<T>; CAP]) -> Option<Self> ⓘ
pub fn from_array_prefix(array: [Option<T>; CAP]) -> Option<Self> ⓘ
Creates a buffer from an array of options by taking the prefix of Some values.
The logical length is inferred as the index of the first None.
Elements after the first None are ignored and need not be None.
Returns None if a None appears before a Some in the prefix.
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 new buffer by cloning all the possible 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 new buffer by copying all the possible elements from src.
Sourcepub const fn capacity(&self) -> NonValueU8<{ u8::MAX }>
pub const fn capacity(&self) -> NonValueU8<{ u8::MAX }>
Returns the fixed capacity of the buffer.
Sourcepub const fn capacity_prim(&self) -> u8
pub const fn capacity_prim(&self) -> u8
Returns the fixed capacity of the buffer.
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_copy(&mut self)where
T: Copy,
pub const fn clear_copy(&mut self)where
T: Copy,
Clears the buffer of Copy elements.
Sourcepub fn truncate(&mut self, new_len: NonValueU8<{ u8::MAX }>)
pub fn truncate(&mut self, new_len: NonValueU8<{ u8::MAX }>)
Truncates the buffer to new_len, dropping excess elements.
If new_len >= len this is a no-op.
Sourcepub const fn truncate_copy(&mut self, new_len: NonValueU8<{ u8::MAX }>)where
T: Copy,
pub const fn truncate_copy(&mut self, new_len: NonValueU8<{ u8::MAX }>)where
T: Copy,
Truncates the buffer of Copy elements to new_len.
If new_len >= len this is a no-op.
Sourcepub fn truncate_prim(&mut self, new_len: u8) -> Result<(), InvalidValue> ⓘ
pub fn truncate_prim(&mut self, new_len: u8) -> Result<(), InvalidValue> ⓘ
Primitive-index variant of truncate,
Sourcepub const fn truncate_prim_copy(
&mut self,
new_len: u8,
) -> Result<(), InvalidValue> ⓘwhere
T: Copy,
pub const fn truncate_prim_copy(
&mut self,
new_len: u8,
) -> Result<(), InvalidValue> ⓘwhere
T: Copy,
Primitive-index variant of truncate_copy,
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 const fn pop_back(&mut self) -> Option<T> ⓘ
pub const fn pop_back(&mut self) -> Option<T> ⓘ
Removes and returns a 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 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 a 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 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 index, filling the gap with the last 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 the value at index, filling the gap with the last 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 const fn as_mut_slice(&mut self) -> &mut [Option<T>] ⓘ
pub const fn as_mut_slice(&mut self) -> &mut [Option<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.
Trait Implementations§
Source§impl<T: Clone, S: Clone> Clone for BufferLinearStaticExample<T, S>
impl<T: Clone, S: Clone> Clone for BufferLinearStaticExample<T, S>
Source§fn clone(&self) -> BufferLinearStaticExample<T, S>
fn clone(&self) -> BufferLinearStaticExample<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 BufferLinearStaticExample<T, S>
Source§impl<T, const CAP: usize> Default for BufferLinearStaticExample<T, [MaybeUninit<T>; CAP]>
impl<T, const CAP: usize> Default for BufferLinearStaticExample<T, [MaybeUninit<T>; CAP]>
impl<T: Eq, S: Eq> Eq for BufferLinearStaticExample<T, S>
Source§impl<T: Ord, S: Ord> Ord for BufferLinearStaticExample<T, S>
impl<T: Ord, S: Ord> Ord for BufferLinearStaticExample<T, S>
Source§fn cmp(&self, other: &BufferLinearStaticExample<T, S>) -> Ordering
fn cmp(&self, other: &BufferLinearStaticExample<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,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialOrd, S: PartialOrd> PartialOrd for BufferLinearStaticExample<T, S>
impl<T: PartialOrd, S: PartialOrd> PartialOrd for BufferLinearStaticExample<T, S>
impl<T: PartialEq, S: PartialEq> StructuralPartialEq for BufferLinearStaticExample<T, S>
Auto Trait Implementations§
impl<T, S> Freeze for BufferLinearStaticExample<T, S>
impl<T, S> RefUnwindSafe for BufferLinearStaticExample<T, S>
impl<T, S> Send for BufferLinearStaticExample<T, S>
impl<T, S> Sync for BufferLinearStaticExample<T, S>
impl<T, S> Unpin for BufferLinearStaticExample<T, S>
impl<T, S> UnsafeUnpin for BufferLinearStaticExample<T, S>
impl<T, S> UnwindSafe for BufferLinearStaticExample<T, S>
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.