Module array

Module array 

Source
Expand description

stack-allocated array structure. similar to Vec in functionality, except Array lives on the ‘stack’, lending it well for scratch arrays.

this structure is basically a lightweight wrapper over a simple [T; N] array type.

§examples

let mut array = Array::<16, _>::new(); // new array with capacity of 16
 
// `Array` functions very similarly to `Vec`.
 
array.push(1);
array.push(2);

assert_eq!(array.len(), 2);
assert_eq!(array[0], 1);
 
assert_eq!(array.pop(), Some(2));
assert_eq!(array.len(), 1);
 
array[0] = 7;
assert_eq!(array[0], 7);
 
array.extend([1, 2, 3]);
 
for x in &array {
    println!("{x}");
}
 
assert_eq!(array, [7, 1, 2, 3]);

note that, while the terminology “stack-allocated” is used here, one can easily allocate this structure onto the heap like so:

let array = Box::new(Array::<16, ()>::new());

of course, at this point, one should consider using Vec or similar.

Structs§

Array
stack-allocated array. see module level documentation for more.
IntoIter
iterator for Array.