diff options
| author | Grant Miller <[email protected]> | 2022-07-25 23:09:07 -0500 |
|---|---|---|
| committer | Grant Miller <[email protected]> | 2022-07-25 23:09:07 -0500 |
| commit | 1d63a30d5f52cc69b4dd606d0f2a12fe4e03f055 (patch) | |
| tree | e2ffe5770eb1468e20d620d174634f10ad4e6f7f | |
| parent | 41e392bda30feae7e57f32872be082b1f15392ac (diff) | |
Forever: Simplify pointer handling
| -rw-r--r-- | embassy/src/util/forever.rs | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/embassy/src/util/forever.rs b/embassy/src/util/forever.rs index 4c2620052..3d2af38b1 100644 --- a/embassy/src/util/forever.rs +++ b/embassy/src/util/forever.rs | |||
| @@ -74,12 +74,8 @@ impl<T> Forever<T> { | |||
| 74 | panic!("Forever.put() called multiple times"); | 74 | panic!("Forever.put() called multiple times"); |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | unsafe { | 77 | let p: &'static mut MaybeUninit<T> = unsafe { &mut *self.t.get() }; |
| 78 | let p = self.t.get(); | 78 | p.write(val()) |
| 79 | let p = (&mut *p).as_mut_ptr(); | ||
| 80 | p.write(val()); | ||
| 81 | &mut *p | ||
| 82 | } | ||
| 83 | } | 79 | } |
| 84 | 80 | ||
| 85 | /// Unsafely get a mutable reference to the contents of this Forever. | 81 | /// Unsafely get a mutable reference to the contents of this Forever. |
| @@ -93,8 +89,7 @@ impl<T> Forever<T> { | |||
| 93 | #[inline(always)] | 89 | #[inline(always)] |
| 94 | #[allow(clippy::mut_from_ref)] | 90 | #[allow(clippy::mut_from_ref)] |
| 95 | pub unsafe fn steal(&self) -> &mut T { | 91 | pub unsafe fn steal(&self) -> &mut T { |
| 96 | let p = self.t.get(); | 92 | let p: &mut MaybeUninit<T> = &mut *self.t.get(); |
| 97 | let p = (&mut *p).as_mut_ptr(); | 93 | p.assume_init_mut() |
| 98 | &mut *p | ||
| 99 | } | 94 | } |
| 100 | } | 95 | } |
