aboutsummaryrefslogtreecommitdiff
path: root/embassy-hal-common
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-04-11 23:00:14 +0200
committerDario Nieuwenhuis <[email protected]>2023-04-11 23:09:02 +0200
commit9a677ab618aa7a7612cd079b77d3240bdb02fdac (patch)
tree17eacc9698a823a8ad5af3fd44468f54e69a5c1d /embassy-hal-common
parent5c42ca13bd207c5923cb36e1454f3f838582b6cb (diff)
common/peripheral: do not require mut in PeripheralRef clone_unchecked.
Diffstat (limited to 'embassy-hal-common')
-rw-r--r--embassy-hal-common/src/macros.rs2
-rw-r--r--embassy-hal-common/src/peripheral.rs12
2 files changed, 7 insertions, 7 deletions
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 {
92 type P = $type; 92 type P = $type;
93 93
94 #[inline] 94 #[inline]
95 unsafe fn clone_unchecked(&mut self) -> Self::P { 95 unsafe fn clone_unchecked(&self) -> Self::P {
96 $type { ..*self } 96 $type { ..*self }
97 } 97 }
98 } 98 }
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> {
39 /// You should strongly prefer using `reborrow()` instead. It returns a 39 /// You should strongly prefer using `reborrow()` instead. It returns a
40 /// `PeripheralRef` that borrows `self`, which allows the borrow checker 40 /// `PeripheralRef` that borrows `self`, which allows the borrow checker
41 /// to enforce this at compile time. 41 /// to enforce this at compile time.
42 pub unsafe fn clone_unchecked(&mut self) -> PeripheralRef<'a, T> 42 pub unsafe fn clone_unchecked(&self) -> PeripheralRef<'a, T>
43 where 43 where
44 T: Peripheral<P = T>, 44 T: Peripheral<P = T>,
45 { 45 {
@@ -146,14 +146,14 @@ pub trait Peripheral: Sized {
146 /// 146 ///
147 /// You should strongly prefer using `into_ref()` instead. It returns a 147 /// You should strongly prefer using `into_ref()` instead. It returns a
148 /// `PeripheralRef`, which allows the borrow checker to enforce this at compile time. 148 /// `PeripheralRef`, which allows the borrow checker to enforce this at compile time.
149 unsafe fn clone_unchecked(&mut self) -> Self::P; 149 unsafe fn clone_unchecked(&self) -> Self::P;
150 150
151 /// Convert a value into a `PeripheralRef`. 151 /// Convert a value into a `PeripheralRef`.
152 /// 152 ///
153 /// When called on an owned `T`, yields a `PeripheralRef<'static, T>`. 153 /// When called on an owned `T`, yields a `PeripheralRef<'static, T>`.
154 /// When called on an `&'a mut T`, yields a `PeripheralRef<'a, T>`. 154 /// When called on an `&'a mut T`, yields a `PeripheralRef<'a, T>`.
155 #[inline] 155 #[inline]
156 fn into_ref<'a>(mut self) -> PeripheralRef<'a, Self::P> 156 fn into_ref<'a>(self) -> PeripheralRef<'a, Self::P>
157 where 157 where
158 Self: 'a, 158 Self: 'a,
159 { 159 {
@@ -161,14 +161,14 @@ pub trait Peripheral: Sized {
161 } 161 }
162} 162}
163 163
164impl<'b, T: DerefMut> Peripheral for T 164impl<'b, T: Deref> Peripheral for T
165where 165where
166 T::Target: Peripheral, 166 T::Target: Peripheral,
167{ 167{
168 type P = <T::Target as Peripheral>::P; 168 type P = <T::Target as Peripheral>::P;
169 169
170 #[inline] 170 #[inline]
171 unsafe fn clone_unchecked(&mut self) -> Self::P { 171 unsafe fn clone_unchecked(&self) -> Self::P {
172 self.deref_mut().clone_unchecked() 172 self.deref().clone_unchecked()
173 } 173 }
174} 174}