Sometimes you run operations that might fail, and you don't care about the specific error details. You just want to know whether the operation succeeded or failed. Rust’s Result<T, E> can be converted into an Option<T> to represent success (Some) or failure (None), discarding the error details.
This challenge builds on the concept of handling Result and converting it to Option. You will write a function that reads the entire content of a file and returns it as an Option<String>.
Implement the function read_file:
&str) as input.String.Some(String) containing the file content.None..ok() method to convert Result into Option and use the ? operator to easily propagate errors if required.Sometimes you run operations that might fail, and you don't care about the specific error details. You just want to know whether the operation succeeded or failed. Rust’s Result<T, E> can be converted into an Option<T> to represent success (Some) or failure (None), discarding the error details.
This challenge builds on the concept of handling Result and converting it to Option. You will write a function that reads the entire content of a file and returns it as an Option<String>.
Implement the function read_file:
&str) as input.String.Some(String) containing the file content.None..ok() method to convert Result into Option and use the ? operator to easily propagate errors if required.