Prior comments:
#[derive(Snafu)]
enum Error {
#[snafu(transparent)]
#[snafu(source(forward))]
DomainA { source: a::Error },
#[snafu(transparent)]
DomainB { source: b::Error },
}
Generated:
impl<T> From<T> for Error
where T: Into<a::Error>
{
fn from(val: T) -> Self {
Self::DomainA { source: val.into() }
}
}
impl From<b::Error> for Error {
fn from(val: b::Error) -> Self {
Self::DomainB { source: val }
}
}
Since Rust does not yet support specialization, I still need to call map_err for T: Into<b::error>. However, a forward From implementation for the most frequently used variant can significantly reduces boilerplate.
Originally posted by @Huliiiiii in #481