rust-lang-deprecated / error-chain

Error boilerplate for Rust
Apache License 2.0
729 stars 111 forks source link

Allow multiple errors to be mapped to single local error #235

Open thegranddesign opened 6 years ago

thegranddesign commented 6 years ago

The reason I sought out this crate was because I wanted to do something like this:

::url::ParseError         => ::my_crate::errors::UrlParseError
::hyper::errors::UriError => ::my_crate::errors::UrlParseError

Unfortunately it doesn't seem like that's currently possible with this crate.

Am I missing something? If not, can it be added?

I'm thinking syntax such as:

foreign_links {
    UrlParseError(::url::ParseError, ::hyper::errors::UriError);
}
Yamakaky commented 6 years ago

Yeah, it's not possible for now because UrlParseError must contain an enum with the two variants.

Lymia commented 6 years ago

You could make a variant in errors { }, and manually write From implementations, maybe? I did that with std::sync::PoisonError (for different reasons)