DEV Community

Discussion on: Learning Rust: A clean start

Collapse
 
ragudos profile image
Aaron • Edited

Awesome! You'd be amazed by the power of traits. Be careful about noisy match statements in error handling though. Try using impl for error types!

For example,

impl From<Error> for MyOwnError {
fn from(err: Error) -> Self {
MyOwnError { message: "oh no! }
}
}

With that, whenever the Error type is returned and we say that the return type of a function when it errors is MyOwnError, the from function will be called.

Good luck!