hd44780_controller/device/
command_ext.rs1use crate::command::*;
2
3use super::*;
4
5pub trait CommandExtSync: SyncDevice {
6 fn execute_command<C, R, E>(&mut self, cmd: &C) -> Result<R, E>
7 where
8 C: SyncCommand<Ret = R, Err = E>,
9 {
10 cmd.execute(self)
11 }
12
13 fn execute_commands<C, E>(&mut self, cmd: &[C]) -> Result<(), E>
14 where
15 C: SyncCommand<Err = E>,
16 {
17 for c in cmd {
18 c.execute(self)?;
19 }
20 Ok(())
21 }
22}
23
24#[cfg(feature = "async")]
25#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
26pub trait CommandExtAsync: AsyncDevice {
27 async fn execute_command_async<C, R, E>(&mut self, cmd: &C) -> Result<R, E>
28 where
29 C: AsyncCommand<Ret = R, Err = E>,
30 {
31 cmd.execute_async(self).await
32 }
33
34 async fn execute_commands_async<C, E>(&mut self, cmd: &[C]) -> Result<(), E>
35 where
36 C: AsyncCommand<Err = E>,
37 {
38 for c in cmd {
39 c.execute_async(self).await?;
40 }
41 Ok(())
42 }
43}
44
45impl<D: SyncDevice> CommandExtSync for D {}
46
47#[cfg(feature = "async")]
48#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
49impl<D: AsyncDevice> CommandExtAsync for D {}