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);

Appends an element to the back of a collection

Examples
use stack_array::Array;

let mut arr: Array<u8, 3> = Array::from([1]);
arr.push(2);
arr.push(3);
assert_eq!(&arr[..], [1, 2, 3]);
Panics

Panics if the array is full.

Removes the last element from a collection and returns it.

Examples
use stack_array::Array;

let mut arr: Array<u8, 3> = Array::from([1, 2]);
assert_eq!(arr.pop(), 2);
assert_eq!(arr.pop(), 1);
assert!(arr.is_empty());
Panics

Panics if the array is empty.

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.

Trait Implementations

Performs the conversion.

Performs the conversion.

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Executes the destructor for this type. Read more

Performs the conversion.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.