Content-Length: 18053 | pFad | https://doc.rust-lang.org/reference/items/../names/../types/../types/array.html#grammar-ArrayType

Array types - The Rust Reference

Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 a constant expression that evaluates to a usize.

Examples:

#![allow(unused)]
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.









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://doc.rust-lang.org/reference/items/../names/../types/../types/array.html#grammar-ArrayType

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy