mirror of
https://github.com/esp-rs/esp-idf-hal.git
synced 2025-09-30 13:50:53 +00:00
Seal the Peripheral trait
This commit is contained in:
parent
905cd5233e
commit
1f69f24773
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 {}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user