embedded_interfaces/commands/
unsupported_executor.rs

1use crate::TransportError;
2
3use super::{Command, Executor, i2c, spi};
4
5/// This dummy executor accepts any command and does nothing when used. If this executor is used,
6/// it means that the associated interface is not supported.
7pub struct UnsupportedExecutor<E: core::fmt::Debug, C: Command + ?Sized> {
8    _marker: core::marker::PhantomData<(E, C)>,
9}
10
11impl<E: core::fmt::Debug, C: Command> Executor for UnsupportedExecutor<E, C> {
12    type Error = E;
13    type Command = C;
14}
15
16#[maybe_async_cfg::maybe(
17    idents(hal(sync = "embedded_hal", async = "embedded_hal_async"), Executor, I2cBoundBus),
18    sync(feature = "sync"),
19    async(feature = "async"),
20    keep_self
21)]
22impl<E: core::fmt::Debug, C: Command> i2c::Executor for UnsupportedExecutor<E, C> {
23    async fn execute<D, I, A>(
24        _delay: &mut D,
25        _bound_bus: &mut crate::i2c::I2cBoundBus<I, A>,
26        _input: C::In,
27    ) -> Result<C::Out, TransportError<Self::Error, I::Error>>
28    where
29        D: hal::delay::DelayNs,
30        I: hal::i2c::I2c<A> + hal::i2c::ErrorType,
31        A: hal::i2c::AddressMode + Copy,
32    {
33        Err(TransportError::Unexpected("unsupported interface"))
34    }
35}
36
37#[maybe_async_cfg::maybe(
38    idents(hal(sync = "embedded_hal", async = "embedded_hal_async"), Executor, I2cBoundBus),
39    sync(feature = "sync"),
40    async(feature = "async"),
41    keep_self
42)]
43impl<E: core::fmt::Debug, C: Command> spi::Executor for UnsupportedExecutor<E, C> {
44    async fn execute<D, I>(
45        _delay: &mut D,
46        _interface: &mut I,
47        _input: C::In,
48    ) -> Result<C::Out, TransportError<Self::Error, I::Error>>
49    where
50        D: hal::delay::DelayNs,
51        I: hal::spi::r#SpiDevice,
52    {
53        Err(TransportError::Unexpected("unsupported interface"))
54    }
55}