diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-09-16 10:32:12 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-09-16 10:32:12 +0000 |
| commit | ec104605479aeeb3906e261ccdde2a0982d44c97 (patch) | |
| tree | 8a5a2d0175e0e57beb6d6de27eff5d507870d099 /embassy-sync/src | |
| parent | 9794bc59cc74598f5131f502153d4288c3261274 (diff) | |
| parent | 79654510b71290632ee659dd2ae1851f33f48374 (diff) | |
Merge #950
950: Add .into_inner() and .get_mut() to Mutex r=Dirbaio a=hulthe
Similar to the methods on std Mutex, these methods allow accessing the underlying data without locking the mutex when you have exclusive access to it.
Co-authored-by: Joakim Hulthe <[email protected]>
Diffstat (limited to 'embassy-sync/src')
| -rw-r--r-- | embassy-sync/src/mutex.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/embassy-sync/src/mutex.rs b/embassy-sync/src/mutex.rs index 75a6e8dd3..92101c6b5 100644 --- a/embassy-sync/src/mutex.rs +++ b/embassy-sync/src/mutex.rs | |||
| @@ -111,6 +111,22 @@ 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 | ||
| 118 | T: Sized, | ||
| 119 | { | ||
| 120 | self.inner.into_inner() | ||
| 121 | } | ||
| 122 | |||
| 123 | /// Returns a mutable reference to the underlying data. | ||
| 124 | /// | ||
| 125 | /// Since this call borrows the Mutex mutably, no actual locking needs to | ||
| 126 | /// take place -- the mutable borrow statically guarantees no locks exist. | ||
| 127 | pub fn get_mut(&mut self) -> &mut T { | ||
| 128 | self.inner.get_mut() | ||
| 129 | } | ||
| 114 | } | 130 | } |
| 115 | 131 | ||
| 116 | /// Async mutex guard. | 132 | /// Async mutex guard. |
