Answers for "rust get array index"

1

get array element rust

//Array declaration. Array sizes must be known at compile time
let my_array: [i32; 5] = [1, 2, 3, 4, 5];

//If the size of the array is not known at compile time. Use a slice or a vector
// This is how you access a element of a array, just type the index of the element between the square brackets
let x = my_array[0]
Posted by: Guest on June-04-2021
0

rust get items in a list with index and value

for (i, x) in items.iter().enumerate() {
    println!("Item {} = {}", i, x);
}
Posted by: Guest on February-23-2021

Browse Popular Code Answers by Language