The wisest of all, in my opinion, is he who can, if only once a month, call himself a fool.
— Fyodor Dostoevsky
Error Handling
NAME wyzer-error-handling - Explicit error propagation and resolution
DESCRIPTION
Wyzer utilizes a functional approach for error handling via a built-in Result enum. Errors are explicit and must be handled.
SYNOPSIS: RESULT ENUM
fn divide(a: u32, b: u32) -> Result<u32, str> {
if b == 0 {
return Err("Division by zero");
}
Ok(a / b)
}
RESULT DETAILS
Result<T, E>: A core enum representing either success (Ok(T)) or failure (Err(E)).return Err(...): Explicitly returns the error variant.
SYNOPSIS: HANDLING
fn main() {
let result = divide(10, 2);
match result {
Result::Ok(value) => { /* ... */ },
Result::Err(msg) => { /* ... */ },
}
}
HANDLING DETAILS
match: Due to exhaustiveness guarantees, developers are forced to explicitly handle both theOkandErrvariants.