Complete the code to unwrap the Option value safely.
let some_number = Some(10); let number = some_number.[1](); println!("Number: {}", number);
The unwrap() method extracts the value inside Some if it exists, otherwise it panics.
Complete the code to unwrap the Option with a custom panic message.
let some_text = Some("hello"); let text = some_text.[1]("No text found!"); println!("Text: {}", text);
The expect() method unwraps the Option and shows the given message if it is None.
Fix the error in unwrapping the Result value with expect.
let result: Result<i32, &str> = Ok(5); let value = result.[1]("Failed to get value"); println!("Value: {}", value);
The expect() method unwraps the Ok value or panics with the given message if it is Err.
Fill both blanks to unwrap an Option and provide a custom panic message.
let maybe_value = Some(42); let value = maybe_value.[1]("[2] not found"); println!("Value is {}", value);
Use expect to unwrap the Option with a message. The message should mention Option to clarify the error source.
Fill all three blanks to unwrap a Result and handle the error with a custom message.
let res: Result<&str, &str> = Err("error"); let val = res.[1]("[2] failed"); println!("Value: {}", [3]);
Use expect to unwrap the Result with a message. The message includes unwrap to indicate the failure point. Finally, print the unwrapped value val.