Rust has expressive error handling capabilities. One main mechanism is via the result enum:
enum Result<T, Error> {
Ok(T),
Err(Error)
}If a function executes successfully, it’ll return an Ok value. Otherwise, it’ll return an Err value. From here, we have two options.
- We can handle the error immediately.
- We can propagate the error forward to the caller function, which will handle it.