diff options
| author | Robert Zieba <[email protected]> | 2025-09-11 14:40:29 -0700 |
|---|---|---|
| committer | Robert Zieba <[email protected]> | 2025-09-12 09:16:32 -0700 |
| commit | 78d5d3f2dde14fcbf4879de19076eb89d9b9ef8b (patch) | |
| tree | 8d27ae1d62076f753928f801ff8ae42e5119852e /embassy-sync/src/mutex.rs | |
| parent | 6cc75315652a1029f032f44b5ccd5d1398da05dd (diff) | |
Remove `Sized` bound from `MutexGuard::map`
Since `MutexGuard` has `T: ?Sized`, `U` does not need to be restricted
to `Sized` types. This now allows using `map` to cast from
`MutexGuard<'_, M, ImplsTrait>` to `MutexGuard<'_, M, dyn Trait>`.
Diffstat (limited to 'embassy-sync/src/mutex.rs')
| -rw-r--r-- | embassy-sync/src/mutex.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/embassy-sync/src/mutex.rs b/embassy-sync/src/mutex.rs index 4ce6dd987..aea682899 100644 --- a/embassy-sync/src/mutex.rs +++ b/embassy-sync/src/mutex.rs | |||
| @@ -187,7 +187,7 @@ where | |||
| 187 | T: ?Sized, | 187 | T: ?Sized, |
| 188 | { | 188 | { |
| 189 | /// Returns a locked view over a portion of the locked data. | 189 | /// Returns a locked view over a portion of the locked data. |
| 190 | pub fn map<U>(this: Self, fun: impl FnOnce(&mut T) -> &mut U) -> MappedMutexGuard<'a, M, U> { | 190 | pub fn map<U: ?Sized>(this: Self, fun: impl FnOnce(&mut T) -> &mut U) -> MappedMutexGuard<'a, M, U> { |
| 191 | let mutex = this.mutex; | 191 | let mutex = this.mutex; |
| 192 | let value = fun(unsafe { &mut *this.mutex.inner.get() }); | 192 | let value = fun(unsafe { &mut *this.mutex.inner.get() }); |
| 193 | // Don't run the `drop` method for MutexGuard. The ownership of the underlying | 193 | // Don't run the `drop` method for MutexGuard. The ownership of the underlying |
| @@ -279,7 +279,7 @@ where | |||
| 279 | T: ?Sized, | 279 | T: ?Sized, |
| 280 | { | 280 | { |
| 281 | /// Returns a locked view over a portion of the locked data. | 281 | /// Returns a locked view over a portion of the locked data. |
| 282 | pub fn map<U>(this: Self, fun: impl FnOnce(&mut T) -> &mut U) -> MappedMutexGuard<'a, M, U> { | 282 | pub fn map<U: ?Sized>(this: Self, fun: impl FnOnce(&mut T) -> &mut U) -> MappedMutexGuard<'a, M, U> { |
| 283 | let state = this.state; | 283 | let state = this.state; |
| 284 | let value = fun(unsafe { &mut *this.value }); | 284 | let value = fun(unsafe { &mut *this.value }); |
| 285 | // Don't run the `drop` method for MutexGuard. The ownership of the underlying | 285 | // Don't run the `drop` method for MutexGuard. The ownership of the underlying |
