Struct stack_array::Array [−][src]
pub struct Array<T, const N: usize> { /* fields omitted */ }
Expand description
A data structure for storing and manipulating fixed number of elements of a specific type.
Implementations
Creates a new Array<T, N>
.
Examples
use stack_array::Array;
let arr = Array::<u8, 4>::new();
// or
let arr: Array<u8, 4> = Array::new();
Returns the number of elements the array can hold.
Examples
use stack_array::Array;
let arr: Array<u8, 4> = Array::new();
assert_eq!(arr.capacity(), 4);
Returns the number of elements currently in the array.
Examples
use stack_array::Array;
let arr: Array<u8, 3> = Array::from([1, 2]);
assert_eq!(arr.len(), 2);
Returns true
, If the array is full.
Examples
use stack_array::Array;
let arr: Array<u8, 3> = Array::from([1, 2]);
assert!(!arr.is_full());
Returns true if the array contains no elements.
Examples
use stack_array::Array;
let mut arr: Array<u8, 2> = Array::new();
assert!(arr.is_empty());
arr.push(1);
assert!(!arr.is_empty());
Returns the number of elements can be inserted into the array.
Examples
use stack_array::Array;
let arr: Array<u8, 3> = Array::from([1, 2]);
assert_eq!(arr.remaining_capacity(), 1);
Clears the array, removing all values.
Examples
use stack_array::Array;
let mut list: Array<u8, 3> = Array::from([1, 2, 3]);
list.clear();
assert!(list.is_empty());
Inserts an element at position index within the array, shifting all elements after it to the right.
Examples
use stack_array::Array;
let mut list: Array<u8, 3> = Array::from([3]);
list.insert(0, 1);
assert_eq!(&list[..], [1, 3]);
list.insert(1, 2);
assert_eq!(&list[..], [1, 2, 3]);
Panics
Panics if the index is out of bounds.
Removes an element from position index within the array, shifting all elements after it to the left.
Examples
use stack_array::Array;
let mut list: Array<u8, 3> = Array::from([1, 2, 3]);
assert_eq!(list.remove(0), 1);
assert_eq!(list.remove(0), 2);
assert_eq!(list.remove(0), 3);
Panics
Panics if the index is out of bounds.