mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-10-30 05:40:55 +00:00
impl Unborrow for &'a mut T
This plays nicer with user code that's generic over peripheral traits like `Instance` or `Pin`.
This commit is contained in:
parent
22e6a35598
commit
dc67d2f4a4
@ -24,14 +24,6 @@ macro_rules! peripherals {
|
||||
}
|
||||
}
|
||||
|
||||
$(#[$cfg])?
|
||||
impl embassy::util::Unborrow for &mut $name {
|
||||
type Target = $name;
|
||||
#[inline]
|
||||
unsafe fn unborrow(self) -> $name {
|
||||
::core::ptr::read(self)
|
||||
}
|
||||
}
|
||||
)*
|
||||
}
|
||||
|
||||
@ -95,14 +87,6 @@ macro_rules! impl_unborrow {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ::embassy::util::Unborrow for &'a mut $type {
|
||||
type Target = $type;
|
||||
#[inline]
|
||||
unsafe fn unborrow(self) -> Self::Target {
|
||||
unsafe { ::core::ptr::read(self) }
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -216,13 +216,6 @@ pub fn interrupt_declare(item: TokenStream) -> TokenStream {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl ::embassy::util::Unborrow for &mut #name_interrupt {
|
||||
type Target = #name_interrupt;
|
||||
unsafe fn unborrow(self) -> #name_interrupt {
|
||||
::core::ptr::read(self)
|
||||
}
|
||||
}
|
||||
};
|
||||
result.into()
|
||||
}
|
||||
|
@ -22,6 +22,13 @@ pub trait Unborrow {
|
||||
unsafe fn unborrow(self) -> Self::Target;
|
||||
}
|
||||
|
||||
impl<'a, T: Unborrow> Unborrow for &'a mut T {
|
||||
type Target = T::Target;
|
||||
unsafe fn unborrow(self) -> Self::Target {
|
||||
T::unborrow(core::ptr::read(self))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Steal {
|
||||
unsafe fn steal() -> Self;
|
||||
}
|
||||
@ -40,17 +47,6 @@ macro_rules! impl_unborrow_tuples {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, $($t),+> Unborrow for &'a mut($($t),+)
|
||||
where
|
||||
$(
|
||||
$t: Unborrow<Target = $t>
|
||||
),+
|
||||
{
|
||||
type Target = ($($t),+);
|
||||
unsafe fn unborrow(self) -> Self::Target {
|
||||
::core::ptr::read(self)
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user