diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index 9b0b35ec..2416005b 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs @@ -148,38 +148,31 @@ struct Timeout { #[allow(dead_code)] impl Timeout { - #[cfg(not(feature = "time"))] #[inline] fn check(self) -> Result<(), Error> { + #[cfg(feature = "time")] + if Instant::now() > self.deadline { + return Err(Error::Timeout); + } + Ok(()) } - #[cfg(feature = "time")] #[inline] - fn check(self) -> Result<(), Error> { - if Instant::now() > self.deadline { - Err(Error::Timeout) - } else { - Ok(()) + fn with(self, fut: impl Future>) -> impl Future> { + #[cfg(feature = "time")] + { + use futures::FutureExt; + + embassy_futures::select::select(embassy_time::Timer::at(self.deadline), fut).map(|r| match r { + embassy_futures::select::Either::First(_) => Err(Error::Timeout), + embassy_futures::select::Either::Second(r) => r, + }) } - } - #[cfg(not(feature = "time"))] - #[inline] - fn with(self, fut: impl Future>) -> impl Future> { + #[cfg(not(feature = "time"))] fut } - - #[cfg(feature = "time")] - #[inline] - fn with(self, fut: impl Future>) -> impl Future> { - use futures::FutureExt; - - embassy_futures::select::select(embassy_time::Timer::at(self.deadline), fut).map(|r| match r { - embassy_futures::select::Either::First(_) => Err(Error::Timeout), - embassy_futures::select::Either::Second(r) => r, - }) - } } pub(crate) mod sealed {