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:
Dario Nieuwenhuis 2021-05-19 22:31:09 +02:00
parent 22e6a35598
commit dc67d2f4a4
3 changed files with 7 additions and 34 deletions

View File

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

View File

@ -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()
}

View File

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