From fcd6f7c19d566d8e80204b3715eb5a15a1fb4bc3 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Wed, 28 Sep 2022 21:55:15 +0000 Subject: [PATCH] Remove unnecessary custom Infallible types --- rp2040-hal/src/spi.rs | 29 +++-------------------------- rp2040-hal/src/uart/utils.rs | 23 ----------------------- rp2040-hal/src/uart/writer.rs | 2 +- 3 files changed, 4 insertions(+), 50 deletions(-) diff --git a/rp2040-hal/src/spi.rs b/rp2040-hal/src/spi.rs index ca158fd..1edd01b 100644 --- a/rp2040-hal/src/spi.rs +++ b/rp2040-hal/src/spi.rs @@ -192,29 +192,6 @@ impl Spi { } } -/// Same as core::convert::Infallible, but implementing spi::Error -/// -/// For eh 1.0.0-alpha.6, Infallible doesn't implement spi::Error, -/// so use a locally defined type instead. -/// This should be removed with the next release of e-h. -/// (https://github.com/rust-embedded/embedded-hal/pull/328) -#[cfg(feature = "eh1_0_alpha")] -pub enum SpiInfallible {} - -#[cfg(feature = "eh1_0_alpha")] -impl core::fmt::Debug for SpiInfallible { - fn fmt(&self, _f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match *self {} - } -} - -#[cfg(feature = "eh1_0_alpha")] -impl eh1::Error for SpiInfallible { - fn kind(&self) -> eh1::ErrorKind { - match *self {} - } -} - macro_rules! impl_write { ($type:ident, [$($nr:expr),+]) => { @@ -250,20 +227,20 @@ macro_rules! impl_write { #[cfg(feature = "eh1_0_alpha")] impl eh1::ErrorType for Spi { - type Error = SpiInfallible; + type Error = Infallible; } /* disabled for now - nb was migrated to separate crate #[cfg(feature = "eh1_0_alpha")] impl eh1::nb::FullDuplex<$type> for Spi { - fn read(&mut self) -> Result<$type, nb::Error> { + fn read(&mut self) -> Result<$type, nb::Error> { if !self.is_readable() { return Err(nb::Error::WouldBlock); } Ok(self.device.sspdr.read().data().bits() as $type) } - fn write(&mut self, word: $type) -> Result<(), nb::Error> { + fn write(&mut self, word: $type) -> Result<(), nb::Error> { // Write to TX FIFO whilst ignoring RX, then clean up afterward. When RX // is full, PL022 inhibits RX pushes, and sets a sticky flag on // push-on-full, but continues shifting. Safe if SSPIMSC_RORIM is not set. diff --git a/rp2040-hal/src/uart/utils.rs b/rp2040-hal/src/uart/utils.rs index 42eb9e6..508207d 100644 --- a/rp2040-hal/src/uart/utils.rs +++ b/rp2040-hal/src/uart/utils.rs @@ -116,26 +116,3 @@ impl Default for UartConfig { } } } - -/// Same as core::convert::Infallible, but implementing serial::Error -/// -/// For eh 1.0.0-alpha.6, Infallible doesn't implement serial::Error, -/// so use a locally defined type instead. -/// This should be removed with the next release of e-h. -/// (https://github.com/rust-embedded/embedded-hal/pull/328) -#[cfg(feature = "eh1_0_alpha")] -pub enum SerialInfallible {} - -#[cfg(feature = "eh1_0_alpha")] -impl core::fmt::Debug for SerialInfallible { - fn fmt(&self, _f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match *self {} - } -} - -#[cfg(feature = "eh1_0_alpha")] -impl eh1_0_alpha::serial::Error for SerialInfallible { - fn kind(&self) -> eh1_0_alpha::serial::ErrorKind { - match *self {} - } -} diff --git a/rp2040-hal/src/uart/writer.rs b/rp2040-hal/src/uart/writer.rs index 89ffe49..4be2ddd 100644 --- a/rp2040-hal/src/uart/writer.rs +++ b/rp2040-hal/src/uart/writer.rs @@ -184,7 +184,7 @@ impl> Write for Writer { #[cfg(feature = "eh1_0_alpha")] impl> eh1::ErrorType for Writer { - type Error = super::utils::SerialInfallible; + type Error = core::convert::Infallible; } /* disabled for now - nb was migrated to separate crate