wiki/dev/lang/rust/array.md
2024-01-09 13:18:39 +03:00

421 B

Arrays.

Create an array.

Specify the type first, then the count.

let array: [i32; 5] = [1, 2, 3, 4, 5]; // Manual init.
let array: [i32; 5] = [0; 5];          // All to zeroes.

Get the array size.

Use .len() method.

let size = array.len();

Create a slice.

Whole array.

let slice = &array;

Partial.

let slice = &array[1..4]; // Slice of: 1, 2, 3.