diff --git a/src/bus/four_wire.rs b/src/bus/four_wire.rs index 42bc997..d7088de 100644 --- a/src/bus/four_wire.rs +++ b/src/bus/four_wire.rs @@ -69,6 +69,7 @@ impl, ChipSelect: OutputPin> ActiveFourWire } } +// Must use map_err, ambiguity prevents From from being implemented #[repr(u8)] pub enum FourWireError { SpiError(SpiError), @@ -87,4 +88,3 @@ impl fmt::Debug for FourWireError> ActiveBus for ActiveThreeWire { &mut self.spi, &mut data_phase[..last_length_written as usize], ) - }) - .map_err(ThreeWireError::SpiError)?; + })?; address += last_length_written; data_phase = &mut data_phase[last_length_written as usize..]; @@ -111,8 +110,7 @@ impl> ActiveBus for ActiveThreeWire { .and_then(|_| Self::transfer_byte(&mut self.spi, control_phase)) .and_then(|_| { Self::write_bytes(&mut self.spi, &data_phase[..last_length_written as usize]) - }) - .map_err(ThreeWireError::SpiError)?; + })?; address += last_length_written; data_phase = &data_phase[last_length_written as usize..]; @@ -130,6 +128,13 @@ impl> ActiveThreeWire { pub enum ThreeWireError { SpiError(SpiError), } + +impl From for ThreeWireError { + fn from(error: SpiError) -> ThreeWireError { + ThreeWireError::SpiError(error) + } +} + impl fmt::Debug for ThreeWireError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( @@ -141,4 +146,3 @@ impl fmt::Debug for ThreeWireError { ) } } -// TODO impl From and remove map_errs