mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-06-07 21:38:58 +08:00
12 lines
379 B
Rust
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())
|
|
}
|
|
}
|