Error Conversion
From implementations.
Why Convert Errors?
Different layers of code produce different error types. To propagate them through one function, you need to convert lower-level errors into a unified type. Rust does this through the From trait.
The From Trait
From<T> defines how to build one type from another. Implementing it for your error type lets you convert source errors into it.
trait From<T> {
fn from(value: T) -> Self;
}All lessons in this course
- Result and the ? Operator
- thiserror
- anyhow
- Error Conversion