Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Derive support for From implementations #275

Open
vorner opened this issue Nov 23, 2018 · 5 comments
Open

Derive support for From implementations #275

vorner opened this issue Nov 23, 2018 · 5 comments

Comments

@vorner
Copy link

vorner commented Nov 23, 2018

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?

@svenstaro
Copy link

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

@solson
Copy link

solson commented Feb 9, 2019

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.

@alexreg
Copy link

alexreg commented Jul 17, 2019

@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.

@withoutboats
Copy link
Contributor

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

@alexreg
Copy link

alexreg commented Jul 18, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants