Skip to content

Commit a6f623b

Browse files
committed
Add a compile_fail doctest
1 parent a75b292 commit a6f623b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

embedded-hal-async/src/spi.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ where
5959
/// .await
6060
/// }
6161
/// ```
62+
///
63+
/// Note that the compiler will prevent you from moving the bus reference outside of the closure
64+
/// ```compile_fail
65+
/// # use embedded_hal_async::spi::{transaction_helper, SpiBus, SpiBusRead, SpiBusWrite, SpiDevice};
66+
/// #
67+
/// # pub async fn smuggle_test<SPI>(mut device: SPI) -> Result<(), SPI::Error>
68+
/// # where
69+
/// # SPI: SpiDevice,
70+
/// # SPI::Bus: SpiBus,
71+
/// # {
72+
/// let mut bus_smuggler: Option<&mut SPI::Bus> = None;
73+
/// transaction_helper!(&mut device, move |bus| async move {
74+
/// bus_smuggler = Some(bus);
75+
/// Ok(())
76+
/// })
77+
/// .await
78+
/// # }
79+
/// ```
6280
macro_rules! spi_transaction_helper {
6381
($device:expr, move |$bus:ident| async move $closure_body:expr) => {
6482
$crate::spi::SpiDevice::transaction($device, move |$bus| {

0 commit comments

Comments
 (0)