diff --git a/src/lib.rs b/src/lib.rs index 11f032452..df31fbf55 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -143,6 +143,8 @@ macro_rules! impl_peripheral_trait { ($type:ident) => { unsafe impl Send for $type {} + impl $crate::peripheral::sealed::Sealed for $type {} + impl $crate::peripheral::Peripheral for $type { type P = $type; diff --git a/src/modem.rs b/src/modem.rs index e5866d423..097ffeaeb 100644 --- a/src/modem.rs +++ b/src/modem.rs @@ -1,6 +1,6 @@ use core::marker::PhantomData; -use crate::peripheral::Peripheral; +use crate::peripheral::{sealed, Peripheral}; #[cfg(not(esp32s2))] pub use split::*; @@ -43,6 +43,8 @@ impl Modem { unsafe impl Send for Modem {} +impl sealed::Sealed for Modem {} + impl Peripheral for Modem { type P = Self; diff --git a/src/peripheral.rs b/src/peripheral.rs index f791b6851..5145bef4f 100644 --- a/src/peripheral.rs +++ b/src/peripheral.rs @@ -131,7 +131,7 @@ impl<'a, T> DerefMut for PeripheralRef<'a, T> { /// /// `.into_ref()` on an owned `T` yields a `PeripheralRef<'static, T>`. /// `.into_ref()` on an `&'a mut T` yields a `PeripheralRef<'a, T>`. -pub trait Peripheral: Sized { +pub trait Peripheral: Sized + sealed::Sealed { /// Peripheral singleton type type P; @@ -160,6 +160,8 @@ pub trait Peripheral: Sized { } } +impl sealed::Sealed for T {} + impl Peripheral for T where T::Target: Peripheral, @@ -171,3 +173,7 @@ where self.deref_mut().clone_unchecked() } } + +pub(crate) mod sealed { + pub trait Sealed {} +}