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

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