Struct stack_array::Array [−][src]
pub struct Array<T, const N: usize> { /* fields omitted */ }
Implementations
Creates a new Array<T, N>
.
Examples
use stack_array::Array;
let array: Array<u8, 4> = Array::new();
// or
let array = Array::<u8, 4>::new();
Returns the number of elements the array can hold.
Examples
use stack_array::Array;
let array: Array<u8, 4> = Array::new();
assert_eq!(array.capacity(), 4);
Returns the number of elements currently in the array.
Examples
use stack_array::Array;
let mut array: Array<u8, 3> = Array::from([1, 2]);
assert_eq!(array.len(), 2);
Examples
use stack_array::Array;
let mut array: Array<u8, 3> = Array::from([1, 2]);
assert!(!array.is_full());
Returns the number of elements can be inserted into the array.
Examples
use stack_array::Array;
let mut array: Array<u8, 3> = Array::from([1, 2]);
assert_eq!(array.remaing(), 1);
Appends an element to the back of a collection
Examples
use stack_array::Array;
let mut list: Array<u8, 3> = Array::from([1]);
list.push(2);
list.push(3);
assert_eq!(&list[..], [1, 2, 3]);
Removes the last element from a collection and returns it.
Examples
use stack_array::Array;
let mut list: Array<u8, 3> = Array::from([1, 2]);
assert_eq!(list.pop(), 2);
assert_eq!(list.pop(), 1);
assert_eq!(list.len(), 0);
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]);
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);