January 2019
Intermediate to advanced
520 pages
14h 32m
English
The preceding parsing needs its own error type to cover both errors—incorrect parsing of numbers, and invalid variants. Let's declare the ColorError type in this section.
Error handling in Rust is particularly easy. There's a Result type that wraps successful and unsuccessful outcomes in a single entity. Result interprets any type as an error type and you can transform one result to another using the try! macro or the ? operator. Joining different error types, however, is much more complicated. There's the std::error::Error trait, which provides a generic interface for all errors, but it's a little clumsy. To create errors in a more user-friendly way, you can use the failure crate.
This crate helps ...
Read now
Unlock full access