For now, this reference is a best-effort document. We strive for validity and completeness, but are not yet there. In the future, the docs and lang teams will work together to figure out how best to do this. Until then, this is a best-effort attempt. If you find something wrong or missing, file an issue or send in a pull request.

Array types

Syntax
ArrayType :
   [ Type ; Expression ]

An array is a fixed-size sequence of N elements of type T. The array type is written as [T; N]. The size is an expression that evaluates to a usize.

Examples:


# #![allow(unused_variables)]
#fn main() {
// A stack-allocated array
let array: [i32; 3] = [1, 2, 3];

// A heap-allocated array, coerced to a slice
let boxed_array: Box<[i32]> = Box::new([1, 2, 3]);
#}

All elements of arrays are always initialized, and access to an array is always bounds-checked in safe methods and operators.

Note: The Vec<T> standard library type provides a heap-allocated resizable array type.