A fixed-size array, denoted [T; N], for the element type, T, and the
non-negative compile time constant size, N.
Arrays values are created either with an explicit expression that lists
each element: [x, y, z] or a repeat expression: [x; N]. The repeat
expression requires that the element type is Copy.
The type [T; N] is Copy if T: Copy.
Arrays of sizes from 0 to 32 (inclusive) implement the following traits if
the element type allows it:
Clone (only if T: Copy)
Debug
IntoIterator (implemented for &[T; N] and &mut [T; N])
PartialEq, PartialOrd, Ord, Eq
Hash
AsRef, AsMut
Borrow, BorrowMut
Default
Arrays coerce to slices ([T]), so their methods can be called on
arrays.
Rust does not currently support generics over the size of an array type.
fn main() {
let mut array: [i32; 3] = [0; 3];
array[1] = 1;
array[2] = 2;
assert_eq!([1, 2], &array[1..]);
// This loop prints: 0 1 2
for x in &array {
print!("{} ", x);
}
}
let mut array: [i32; 3] = [0; 3];
array[1] = 1;
array[2] = 2;
assert_eq!([1, 2], &array[1..]);
for x in &array {
print!("{} ", x);
}
Trait Implementations
impl<T> Ord for [T; 32] where T: Ord1.0.0
impl<T> Eq for [T; 32] where T: Eq1.0.0
impl<T> Hash for [T; 32] where T: Hash1.0.0
impl<T> Ord for [T; 31] where T: Ord1.0.0
impl<T> Eq for [T; 31] where T: Eq1.0.0
impl<T> Hash for [T; 31] where T: Hash1.0.0
impl<T> Ord for [T; 30] where T: Ord1.0.0
impl<T> Eq for [T; 30] where T: Eq1.0.0
impl<T> Hash for [T; 30] where T: Hash1.0.0
impl<T> Ord for [T; 29] where T: Ord1.0.0
impl<T> Eq for [T; 29] where T: Eq1.0.0
impl<T> Hash for [T; 29] where T: Hash1.0.0
impl<T> Ord for [T; 28] where T: Ord1.0.0
impl<T> Eq for [T; 28] where T: Eq1.0.0
impl<T> Hash for [T; 28] where T: Hash1.0.0
impl<T> Ord for [T; 27] where T: Ord1.0.0
impl<T> Eq for [T; 27] where T: Eq1.0.0
impl<T> Hash for [T; 27] where T: Hash1.0.0
impl<T> Ord for [T; 26] where T: Ord1.0.0
impl<T> Eq for [T; 26] where T: Eq1.0.0
impl<T> Hash for [T; 26] where T: Hash1.0.0
impl<T> Ord for [T; 25] where T: Ord1.0.0
impl<T> Eq for [T; 25] where T: Eq1.0.0
impl<T> Hash for [T; 25] where T: Hash1.0.0
impl<T> Ord for [T; 24] where T: Ord1.0.0
impl<T> Eq for [T; 24] where T: Eq1.0.0
impl<T> Hash for [T; 24] where T: Hash1.0.0
impl<T> Ord for [T; 23] where T: Ord1.0.0
impl<T> Eq for [T; 23] where T: Eq1.0.0
impl<T> Hash for [T; 23] where T: Hash1.0.0
impl<T> Ord for [T; 22] where T: Ord1.0.0
impl<T> Eq for [T; 22] where T: Eq1.0.0
impl<T> Hash for [T; 22] where T: Hash1.0.0
impl<T> Ord for [T; 21] where T: Ord1.0.0
impl<T> Eq for [T; 21] where T: Eq1.0.0
impl<T> Hash for [T; 21] where T: Hash1.0.0
impl<T> Ord for [T; 20] where T: Ord1.0.0
impl<T> Eq for [T; 20] where T: Eq1.0.0
impl<T> Hash for [T; 20] where T: Hash1.0.0
impl<T> Ord for [T; 19] where T: Ord1.0.0
impl<T> Eq for [T; 19] where T: Eq1.0.0
impl<T> Hash for [T; 19] where T: Hash1.0.0
impl<T> Ord for [T; 18] where T: Ord1.0.0
impl<T> Eq for [T; 18] where T: Eq1.0.0
impl<T> Hash for [T; 18] where T: Hash1.0.0
impl<T> Ord for [T; 17] where T: Ord1.0.0
impl<T> Eq for [T; 17] where T: Eq1.0.0
impl<T> Hash for [T; 17] where T: Hash1.0.0
impl<T> Ord for [T; 16] where T: Ord1.0.0
impl<T> Eq for [T; 16] where T: Eq1.0.0
impl<T> Hash for [T; 16] where T: Hash1.0.0
impl<T> Ord for [T; 15] where T: Ord1.0.0
impl<T> Eq for [T; 15] where T: Eq1.0.0
impl<T> Hash for [T; 15] where T: Hash1.0.0
impl<T> Ord for [T; 14] where T: Ord1.0.0
impl<T> Eq for [T; 14] where T: Eq1.0.0
impl<T> Hash for [T; 14] where T: Hash1.0.0
impl<T> Ord for [T; 13] where T: Ord1.0.0
impl<T> Eq for [T; 13] where T: Eq1.0.0
impl<T> Hash for [T; 13] where T: Hash1.0.0
impl<T> Ord for [T; 12] where T: Ord1.0.0
impl<T> Eq for [T; 12] where T: Eq1.0.0
impl<T> Hash for [T; 12] where T: Hash1.0.0
impl<T> Ord for [T; 11] where T: Ord1.0.0
impl<T> Eq for [T; 11] where T: Eq1.0.0
impl<T> Hash for [T; 11] where T: Hash1.0.0
impl<T> Ord for [T; 10] where T: Ord1.0.0
impl<T> Eq for [T; 10] where T: Eq1.0.0
impl<T> Hash for [T; 10] where T: Hash1.0.0
impl<T> Ord for [T; 9] where T: Ord1.0.0
impl<T> Eq for [T; 9] where T: Eq1.0.0
impl<T> Hash for [T; 9] where T: Hash1.0.0
impl<T> Clone for [T; 9] where T: Copy1.0.0
impl<T> Ord for [T; 8] where T: Ord1.0.0
impl<T> Eq for [T; 8] where T: Eq1.0.0
impl<T> Hash for [T; 8] where T: Hash1.0.0
impl<T> Clone for [T; 8] where T: Copy1.0.0
impl<T> Ord for [T; 7] where T: Ord1.0.0
impl<T> Eq for [T; 7] where T: Eq1.0.0
impl<T> Hash for [T; 7] where T: Hash1.0.0
impl<T> Clone for [T; 7] where T: Copy1.0.0
impl<T> Ord for [T; 6] where T: Ord1.0.0
impl<T> Eq for [T; 6] where T: Eq1.0.0
impl<T> Hash for [T; 6] where T: Hash1.0.0
impl<T> Clone for [T; 6] where T: Copy1.0.0
impl<T> Ord for [T; 5] where T: Ord1.0.0
impl<T> Eq for [T; 5] where T: Eq1.0.0
impl<T> Hash for [T; 5] where T: Hash1.0.0
impl<T> Clone for [T; 5] where T: Copy1.0.0
impl<T> Ord for [T; 4] where T: Ord1.0.0
impl<T> Eq for [T; 4] where T: Eq1.0.0
impl<T> Hash for [T; 4] where T: Hash1.0.0
impl<T> Clone for [T; 4] where T: Copy1.0.0
impl<T> Ord for [T; 3] where T: Ord1.0.0
impl<T> Eq for [T; 3] where T: Eq1.0.0
impl<T> Hash for [T; 3] where T: Hash1.0.0
impl<T> Clone for [T; 3] where T: Copy1.0.0
impl<T> Ord for [T; 2] where T: Ord1.0.0
impl<T> Eq for [T; 2] where T: Eq1.0.0
impl<T> Hash for [T; 2] where T: Hash1.0.0
impl<T> Clone for [T; 2] where T: Copy1.0.0
impl<T> Ord for [T; 1] where T: Ord1.0.0
impl<T> Eq for [T; 1] where T: Eq1.0.0
impl<T> Hash for [T; 1] where T: Hash1.0.0
impl<T> Clone for [T; 1] where T: Copy1.0.0
impl<T> Ord for [T; 0] where T: Ord1.0.0
impl<T> Eq for [T; 0] where T: Eq1.0.0
impl<T> Hash for [T; 0] where T: Hash1.0.0
impl<T> Clone for [T; 0] where T: Copy1.0.0