From 9a677ab618aa7a7612cd079b77d3240bdb02fdac Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 11 Apr 2023 23:00:14 +0200 Subject: common/peripheral: do not require mut in PeripheralRef clone_unchecked. --- embassy-hal-common/src/macros.rs | 2 +- embassy-hal-common/src/peripheral.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'embassy-hal-common/src') diff --git a/embassy-hal-common/src/macros.rs b/embassy-hal-common/src/macros.rs index da7913136..5e62e048a 100644 --- a/embassy-hal-common/src/macros.rs +++ b/embassy-hal-common/src/macros.rs @@ -92,7 +92,7 @@ macro_rules! impl_peripheral { type P = $type; #[inline] - unsafe fn clone_unchecked(&mut self) -> Self::P { + unsafe fn clone_unchecked(&self) -> Self::P { $type { ..*self } } } diff --git a/embassy-hal-common/src/peripheral.rs b/embassy-hal-common/src/peripheral.rs index 4a6b6a600..c7133bac6 100644 --- a/embassy-hal-common/src/peripheral.rs +++ b/embassy-hal-common/src/peripheral.rs @@ -39,7 +39,7 @@ impl<'a, T> PeripheralRef<'a, T> { /// You should strongly prefer using `reborrow()` instead. It returns a /// `PeripheralRef` that borrows `self`, which allows the borrow checker /// to enforce this at compile time. - pub unsafe fn clone_unchecked(&mut self) -> PeripheralRef<'a, T> + pub unsafe fn clone_unchecked(&self) -> PeripheralRef<'a, T> where T: Peripheral

, { @@ -146,14 +146,14 @@ pub trait Peripheral: Sized { /// /// You should strongly prefer using `into_ref()` instead. It returns a /// `PeripheralRef`, which allows the borrow checker to enforce this at compile time. - unsafe fn clone_unchecked(&mut self) -> Self::P; + unsafe fn clone_unchecked(&self) -> Self::P; /// Convert a value into a `PeripheralRef`. /// /// When called on an owned `T`, yields a `PeripheralRef<'static, T>`. /// When called on an `&'a mut T`, yields a `PeripheralRef<'a, T>`. #[inline] - fn into_ref<'a>(mut self) -> PeripheralRef<'a, Self::P> + fn into_ref<'a>(self) -> PeripheralRef<'a, Self::P> where Self: 'a, { @@ -161,14 +161,14 @@ pub trait Peripheral: Sized { } } -impl<'b, T: DerefMut> Peripheral for T +impl<'b, T: Deref> Peripheral for T where T::Target: Peripheral, { type P = ::P; #[inline] - unsafe fn clone_unchecked(&mut self) -> Self::P { - self.deref_mut().clone_unchecked() + unsafe fn clone_unchecked(&self) -> Self::P { + self.deref().clone_unchecked() } } -- cgit