Option Propagation in Rust
In the previous challenge, you learned how to propagate errors using the Result<T, E> type for file handling. Rust also lets you use the ? operator to propagate Option<T> values, but instead of propagating the error it will convert the Option<T> into a None value if it is None.
This challenge focuses on propagating Option values and handling scenarios where optional values might be missing.
Your Task
Implement the function find_and_multiply:
- It takes three parameters:
- A vector of integers (
Vec<i32>). - Two indices (
usizevalues).
- A vector of integers (
- The function retrieves the integers at the two specified indices from the vector.
- If both indices are valid, it returns the product of the two integers as an
Option<i32>. - If any index is out of bounds, the function returns
None. - Use the
?operator to propagateNonevalues.
No run yet
Press
Run to execute your code and see test results here.