Seal the Peripheral trait

This commit is contained in:
Ivan Markov 2022-08-31 12:28:36 +00:00
parent 905cd5233e
commit 1f69f24773
3 changed files with 12 additions and 2 deletions

View File

@ -143,6 +143,8 @@ macro_rules! impl_peripheral_trait {
($type:ident) => { ($type:ident) => {
unsafe impl Send for $type {} unsafe impl Send for $type {}
impl $crate::peripheral::sealed::Sealed for $type {}
impl $crate::peripheral::Peripheral for $type { impl $crate::peripheral::Peripheral for $type {
type P = $type; type P = $type;

View File

@ -1,6 +1,6 @@
use core::marker::PhantomData; use core::marker::PhantomData;
use crate::peripheral::Peripheral; use crate::peripheral::{sealed, Peripheral};
#[cfg(not(esp32s2))] #[cfg(not(esp32s2))]
pub use split::*; pub use split::*;
@ -43,6 +43,8 @@ impl Modem {
unsafe impl Send for Modem {} unsafe impl Send for Modem {}
impl sealed::Sealed for Modem {}
impl Peripheral for Modem { impl Peripheral for Modem {
type P = Self; type P = Self;

View File

@ -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 owned `T` yields a `PeripheralRef<'static, T>`.
/// `.into_ref()` on an `&'a mut T` yields a `PeripheralRef<'a, 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 /// Peripheral singleton type
type P; type P;
@ -160,6 +160,8 @@ pub trait Peripheral: Sized {
} }
} }
impl<T: DerefMut> sealed::Sealed for T {}
impl<T: DerefMut> Peripheral for T impl<T: DerefMut> Peripheral for T
where where
T::Target: Peripheral, T::Target: Peripheral,
@ -171,3 +173,7 @@ where
self.deref_mut().clone_unchecked() self.deref_mut().clone_unchecked()
} }
} }
pub(crate) mod sealed {
pub trait Sealed {}
}