failure icon indicating copy to clipboard operation
failure copied to clipboard

Derive support for From implementations

Open vorner opened this issue 7 years ago • 5 comments

Oftentimes, a custom error is an enum with variants, some of which are just wrappers around some foreign errors/causes.

The derive machinery allows for marking the field as #[cause], like this:

https://boats.gitlab.io/failure/derive-fail.html#overriding-cause

Would it make sense to add possibility to also derive From for such a newtype-style variant, eg by adding #[from] attribute to it?

vorner avatar Nov 23 '18 14:11 vorner

I'm in support of this, but you should see #10.

svenstaro avatar Jan 05 '19 16:01 svenstaro

I would like this, too. I accept the points made in the old discussion regarding context, but often I am implementing a simple parser with only a single I/O operation in the whole file (reading the next line), and I want to capture the io::Error in my error enum so I can use ? cleanly.

It would be that much smoother of an experience if I could just add #[from] and keep focusing on the happy path of this fairly simple code.

solson avatar Feb 09 '19 20:02 solson

@withoutboats Any new thoughts on this? Adding the from attribute as discussed previously seems to be widely desirable, and not too difficult, no? It doesn't get in the way of any existing design principles either.

alexreg avatar Jul 17 '19 16:07 alexreg

I'm no longer actively involved in maintaining this library, not the correct person to ping. :)

withoutboats avatar Jul 17 '19 16:07 withoutboats

@withoutboats Ah my bad; I wasn't aware.

alexreg avatar Jul 18 '19 01:07 alexreg