Skip to content

Commit

Permalink
Implement Drop for Mutex to drop the contents of the inner MaybeUninit
Browse files Browse the repository at this point in the history
  • Loading branch information
jannic committed Sep 19, 2024
1 parent f0cd528 commit f1e3b70
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ impl<T: Default> Mutex<RefCell<T>> {
}
}

impl<T> Drop for Mutex<T> {
fn drop(&mut self) {
// Safety: inner is always initialized
core::mem::drop(unsafe { self.inner.assume_init() });
}
}

// NOTE A `Mutex` can be used as a channel so the protected data must be `Send`
// to prevent sending non-Sendable stuff (e.g. access tokens) across different
// threads.
Expand Down

0 comments on commit f1e3b70

Please sign in to comment.