Complete the code to access the first element of the array.
let numbers = [10, 20, 30]; let first = numbers[[1]];
Arrays in Rust start at index 0, so the first element is at index 0.
Complete the code to access the last element of the vector.
let mut vec = vec![5, 10, 15]; let last = vec[[1]];
The last element of a vector with 3 elements is at index 2 (counting from 0).
Fix the error in accessing the element safely using get method.
let arr = [100, 200, 300]; let value = arr.get([1]).unwrap();
The get method returns an Option. Using index 1 safely accesses the second element.
Fill both blanks to create a HashMap and access a value by key.
use std::collections::HashMap; let mut map = HashMap::new(); map.insert([1], 42); let value = map.get(&[2]).unwrap();
We insert the key "age" and then access it by the same key "age".
Fill all three blanks to access a character from a string slice.
let text = "hello"; let ch = text.chars().nth([1]).[2](); println!("[3]", ch);
We get the first character (index 0), unwrap the Option, and print it using the placeholder {}.
