Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

If Let Option

Use if let to check if a vector has an element at index 2. If it does, print it. If not, print a fallback message.

Expected output:

text
Found: cherry

Hints:

  • Create vec!["apple", "banana", "cherry"]
  • Use if let Some(fruit) = fruits.get(2) { ... }
  • The else branch handles None
rust
fn main() {
}