Files
msg-tool/src/ext/mutex.rs
2025-09-14 11:48:42 +08:00

12 lines
379 B
Rust

//! Extension for [std::sync::Mutex].
pub trait MutexExt<T> {
/// Lock the mutex, blocking the current thread until it can be acquired.
fn lock_blocking(&self) -> std::sync::MutexGuard<'_, T>;
}
impl<T> MutexExt<T> for std::sync::Mutex<T> {
fn lock_blocking(&self) -> std::sync::MutexGuard<'_, T> {
self.lock().unwrap_or_else(|err| err.into_inner())
}
}