How do I wrap multiple generic error types around a custom Error enum in Rust. Its pretty straightforward, I just want this to work.
enum Error<SPIE, PINE> {
SpiError(SPIE),
PinError(PINE),
// other custom errors
}
impl<SPIE,PINE> From<SPIE> for Error<SPIE,PINE> {
fn from(value: SPIE) -> Self {
Self::SpiError(value)
}
}
impl<SPIE,PINE> From<PINE> for Error<SPIE,PINE> {
fn from(value: PINE) -> Self {
Self::PinError(value)
}
}
Instead the compiler complains that:
conflicting implementations of trait `From<_>` for type `Error<_, _>`
which I understand, but perhaps I can distinguish the two types somehow...
Based on the accepted answer, ended up using this:
use Error::Pin;
enum Error<SPIE, PINE> {
Spi(SPIE),
Pin(PINE),
// other custom errors
}
impl<SPIE, PINE> From<SPIE> for Error<SPIE,PINE> {
fn from(value: SPIE) -> Self {
Self::Spi(value)
}
}
and mapping the errors like so: ce.set_low().map_err(Pin)?;