I have a type Foo
whose methods may "raise" errors of an associated type Foo::Err
.
pub trait Foo {
type Err;
Typically you don't do a "merge", but instead use nested errors, like this.
enum IntError {
Overflow,
Underflow
}
enum StrError {
TooLong,
TooShort,
}
enum GenericError {
Int(IntError),
Str(StrError),
}
impl From for GenericError {
fn from(e: IntError) -> Self {
GenericError::Int(e)
}
}
impl From for GenericError {
fn from(e: StrError) -> Self {
GenericError::Str(e)
}
}