Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Result has no method called "unwrap()"?

Tags:

rust

People also ask

What is unwrap() in Rust?

To “unwrap” something in Rust is to say, “Give me the result of the computation, and if there was an error, panic and stop the program.” It would be better if we showed the code for unwrapping because it is so simple, but to do that, we will first need to explore the Option and Result types.

What does OK Do rust?

It is an enum with the variants, Ok(T) , representing success and containing a value, and Err(E) , representing error and containing an error value. Functions return Result whenever errors are expected and recoverable.


If you read the documentation for Result::unwrap, you'll note that it's under a little section called:

impl<T, E> Result<T, E> 
    where E: Debug

This means the methods in that section only exist so long as the given constraints are satisfied.

The only reason unwrap wouldn't exist is that Error doesn't implement Debug.