diff options
| author | Joakim Hulthe <[email protected]> | 2022-09-16 10:32:43 +0200 |
|---|---|---|
| committer | Joakim Hulthe <[email protected]> | 2022-09-16 10:32:43 +0200 |
| commit | 70a3b85acc3b87abab5a66b1a02da033789b5e1a (patch) | |
| tree | f57d1e82d98abd0d897b6fbf7fb63462ba251d4e /embassy-sync/src/mutex.rs | |
| parent | 9794bc59cc74598f5131f502153d4288c3261274 (diff) | |
Add .into_inner() and .get_mut() to Mutex
Diffstat (limited to 'embassy-sync/src/mutex.rs')
| -rw-r--r-- | embassy-sync/src/mutex.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/embassy-sync/src/mutex.rs b/embassy-sync/src/mutex.rs index 75a6e8dd3..a792cf070 100644 --- a/embassy-sync/src/mutex.rs +++ b/embassy-sync/src/mutex.rs | |||
| @@ -111,6 +111,20 @@ where | |||
| 111 | 111 | ||
| 112 | Ok(MutexGuard { mutex: self }) | 112 | Ok(MutexGuard { mutex: self }) |
| 113 | } | 113 | } |
| 114 | |||
| 115 | /// Consumes this mutex, returning the underlying data. | ||
| 116 | pub fn into_inner(self) -> T | ||
| 117 | where T: Sized { | ||
| 118 | self.inner.into_inner() | ||
| 119 | } | ||
| 120 | |||
| 121 | /// Returns a mutable reference to the underlying data. | ||
| 122 | /// | ||
| 123 | /// Since this call borrows the Mutex mutably, no actual locking needs to | ||
| 124 | /// take place -- the mutable borrow statically guarantees no locks exist. | ||
| 125 | pub fn get_mut(&mut self) -> &mut T { | ||
| 126 | self.inner.get_mut() | ||
| 127 | } | ||
| 114 | } | 128 | } |
| 115 | 129 | ||
| 116 | /// Async mutex guard. | 130 | /// Async mutex guard. |
