Array
Array<Type, N> is an stack-allocated vector of maximum capacity N, but not restricted to having an exact amount of elements as [Type; N].
Usage
use Array;
let mut array = new;
array.push;
array.push;
array.extend;
The Array type exposes an API similar to that of Vec with common functions:
.push(Type) -> (),.pop() -> Option<Type>,.extend(IntoIterator<Item = Type>) -> (),.clear() -> (),.insert(usize, Type) -> (),.remove(usize) -> Type,.swap_remove(usize) -> Type,.retain(impl FnMut(&mut Type) -> bool) -> (),.dedup() -> (),.dedup_with(impl FnMut(&mut Type, &mut Type) -> bool) -> (),.dedup_by_key<K: PartialEq>(impl FnMut(&mut Type) -> K) -> (),.drain(impl RangeBounds<usize>) -> Self
The type implements Deref<Target = [Type]> along with DerefMut to access the methods of the slice type. There are also specialized functions for resizing the array.
Furthermore, most of its methods and implementations use cutting-edge nightly const-features, which allows for complex compile-time constants:
use Array;
static ARRAY: = const ;
Performance
Array is stack-allocated, which means it does not make use of any allocator and maintains items inlined on the runtime stack or in the program memory.
Array |
Vec |
ArrayVec |
SmallVec |
|
|---|---|---|---|---|
pushpop |
866M/s | 827M/s | 830M/s | 260M/s |
Iterations per second, measured with
rustc 1.100.0-nightly (e71c0f1e3 2026-08-18)on a MacBook M4.
When to use this type
This type should be used when you need to store a finite and reasonable number of elements in a list, and you care about performance.