From 19802b39b8d51db2c1b83969683e150b7ae0036a Mon Sep 17 00:00:00 2001 From: t-wallet Date: Tue, 2 Dec 2025 15:14:34 +0100 Subject: [PATCH] Implement Into when spi::DeviceError is infallible This improves integration with infallible SPI device driver APIs that constrain the SPI device error type to Into, allowing types such as DeviceError to be used. --- embedded-hal-bus/src/spi/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/embedded-hal-bus/src/spi/mod.rs b/embedded-hal-bus/src/spi/mod.rs index 65972628..c4b66250 100644 --- a/embedded-hal-bus/src/spi/mod.rs +++ b/embedded-hal-bus/src/spi/mod.rs @@ -1,5 +1,6 @@ //! `SpiDevice` implementations. +use core::convert::Infallible; use core::fmt::{self, Debug, Display, Formatter}; use embedded_hal::spi::{Error, ErrorKind}; @@ -63,6 +64,15 @@ where } } +impl From> for Infallible { + fn from(value: DeviceError) -> Self { + match value { + DeviceError::Spi(e) => e, + DeviceError::Cs(e) => e, + } + } +} + /// Dummy [`DelayNs`](embedded_hal::delay::DelayNs) implementation that panics on use. #[derive(Copy, Clone, Eq, PartialEq, Debug)] #[cfg_attr(feature = "defmt-03", derive(defmt::Format))]