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) => {
unsafe impl Send for $type {}
impl $crate::peripheral::sealed::Sealed for $type {}
impl $crate::peripheral::Peripheral for $type {
type P = $type;

View File

@ -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;

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 `&'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<T: DerefMut> sealed::Sealed for T {}
impl<T: DerefMut> Peripheral for T
where
T::Target: Peripheral,
@ -171,3 +173,7 @@ where
self.deref_mut().clone_unchecked()
}
}
pub(crate) mod sealed {
pub trait Sealed {}
}