pub struct StackVec<T, const N: usize> { /* private fields */ }Expand description
A stack-allocated vector with compile-time capacity N.
This type provides Vec-like functionality without heap allocation,
making it suitable for use in audio processing hot paths where
allocation latency is unacceptable.
§Examples
use bbx_core::StackVec;
let mut vec: StackVec<i32, 4> = StackVec::new();
vec.push(1).unwrap();
vec.push(2).unwrap();
assert_eq!(vec.len(), 2);
assert_eq!(vec[0], 1);Implementations§
Source§impl<T, const N: usize> StackVec<T, N>
impl<T, const N: usize> StackVec<T, N>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new empty StackVec.
This is a const fn and can be used in const contexts.
Sourcepub fn push(&mut self, value: T) -> Result<(), T>
pub fn push(&mut self, value: T) -> Result<(), T>
Pushes a value onto the end of the vector.
Returns Ok(()) if successful, or Err(value) if the vector is full.
Sourcepub fn push_unchecked(&mut self, value: T)
pub fn push_unchecked(&mut self, value: T)
Pushes a value onto the end of the vector without bounds checking.
§Panics
Panics in debug mode if the vector is full. In release mode, this will not panic but the behavior is safe due to the debug assertion.
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Returns a mutable slice of the initialized elements.
Trait Implementations§
Source§impl<'a, T, const N: usize> IntoIterator for &'a StackVec<T, N>
impl<'a, T, const N: usize> IntoIterator for &'a StackVec<T, N>
Source§impl<'a, T, const N: usize> IntoIterator for &'a mut StackVec<T, N>
impl<'a, T, const N: usize> IntoIterator for &'a mut StackVec<T, N>
Source§impl<T, const N: usize> IntoIterator for StackVec<T, N>
impl<T, const N: usize> IntoIterator for StackVec<T, N>
Auto Trait Implementations§
impl<T, const N: usize> Freeze for StackVec<T, N>where
T: Freeze,
impl<T, const N: usize> RefUnwindSafe for StackVec<T, N>where
T: RefUnwindSafe,
impl<T, const N: usize> Send for StackVec<T, N>where
T: Send,
impl<T, const N: usize> Sync for StackVec<T, N>where
T: Sync,
impl<T, const N: usize> Unpin for StackVec<T, N>where
T: Unpin,
impl<T, const N: usize> UnwindSafe for StackVec<T, N>where
T: UnwindSafe,
Blanket Implementations§
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
Mutably borrows from an owned value. Read more