rust how to access elements of an array

To access elements of an array in Rust, you can use indexing. Array indexing starts at 0, so the first element of an array is accessed using index 0, the second element with index 1, and so on. Here's an example:

fn main() {
    let arr = [1, 2, 3, 4, 5];

    // Accessing elements of the array
    let first_element = arr[0];
    let second_element = arr[1];
    let third_element = arr[2];

    println!("First element: {}", first_element);
    println!("Second element: {}", second_element);
    println!("Third element: {}", third_element);
}

In this example, we have an array arr with elements [1, 2, 3, 4, 5]. We access the elements of the array using square brackets [] and the corresponding index. The values of the first, second, and third elements are then printed.

Please note that Rust arrays have a fixed size determined at compile-time. If you need a dynamically-sized array, you can use a Vec (vector) instead.

I hope this helps!