Skip to content

Commit 19802b3

Browse files
committed
Implement Into<Infallible> when spi::DeviceError is infallible
This improves integration with infallible SPI device driver APIs that constrain the SPI device error type to Into<Infallible>, allowing types such as DeviceError<Infallible, Infallible> to be used.
1 parent 4e653a7 commit 19802b3

File tree

1 file changed

+10
-0
lines changed
  • embedded-hal-bus/src/spi

1 file changed

+10
-0
lines changed

embedded-hal-bus/src/spi/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! `SpiDevice` implementations.
22
3+
use core::convert::Infallible;
34
use core::fmt::{self, Debug, Display, Formatter};
45
use embedded_hal::spi::{Error, ErrorKind};
56

@@ -63,6 +64,15 @@ where
6364
}
6465
}
6566

67+
impl From<DeviceError<Infallible, Infallible>> for Infallible {
68+
fn from(value: DeviceError<Infallible, Infallible>) -> Self {
69+
match value {
70+
DeviceError::Spi(e) => e,
71+
DeviceError::Cs(e) => e,
72+
}
73+
}
74+
}
75+
6676
/// Dummy [`DelayNs`](embedded_hal::delay::DelayNs) implementation that panics on use.
6777
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
6878
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]

0 commit comments

Comments
 (0)