Skip to main content

tuwunel_core/utils/
arrayvec.rs

1//! Extensions for fixed-capacity `ArrayVec` values.
2//!
3//! The module adds fluent slice extension while preserving the collection's
4//! fixed storage budget. Capacity exhaustion remains explicit through a panic.
5
6use ::arrayvec::ArrayVec;
7
8/// Adds fluent slice extension to fixed-capacity vectors.
9///
10/// Elements are copied into the vector's inline storage. The returned mutable
11/// reference permits continued method chaining.
12pub trait ArrayVecExt<T> {
13	/// Appends every element from `other` and returns the vector.
14	///
15	/// The operation copies the slice without allocating fallback storage. On
16	/// success, each slice element is appended in order.
17	///
18	/// # Panics
19	///
20	/// Panics when the remaining capacity cannot hold the entire slice.
21	fn extend_from_slice(&mut self, other: &[T]) -> &mut Self;
22}
23
24impl<T: Copy, const CAP: usize> ArrayVecExt<T> for ArrayVec<T, CAP> {
25	#[inline]
26	fn extend_from_slice(&mut self, other: &[T]) -> &mut Self {
27		self.try_extend_from_slice(other)
28			.expect("Insufficient buffer capacity to extend from slice");
29
30		self
31	}
32}