4 ms·
I would love a `#[derive(From)]` for newtype structs and enum variants. Would bring Rust error handling back below Java in boilerplate levels. :)
by Rusky 9y ago
I would love a `#[derive(From)]` for newtype structs and enum variants. Would bring Rust error handling back below Java in boilerplate levels. :)
- killercup 9y agoThere are some crates that add a derive for errors, but most people tend to use error-chain or quick-error. Both give you the boilerplate pretty much for free, with various other advantages. E.g., using error-chain, you can just write the above code as error_chain! { foreign_links { Io(io::Error); Parse(ParseIntError); } } and it'll even generate an aliased `Result` type as well as fancy chaining support.
- Rusky 9y agoRight- error_chain is just a bit too much magic for me compared to what #[derive(From)] would do.
- steveklabnik 9y agoCheck out https://crates.io/crates/newtype_derive https://crates.io/crates/newtype_derive
- twic 9y agoVery nice. Now we just need enum variants to be first-class types, and some syntax for deriving on them.