Add MutexExt trait

This commit is contained in:
Sosthene 2024-09-23 12:43:56 +02:00
parent 97df8ea13d
commit 3cbe77c143

View File

@ -1,6 +1,10 @@
use std::sync::{Mutex, MutexGuard};
use std::fmt::Debug;
pub use sp_client;
pub use uuid;
pub use log;
pub use aes_gcm;
pub mod crypto;
pub mod device;
@ -11,3 +15,16 @@ pub mod prd;
pub mod process;
pub mod silentpayments;
pub mod signature;
pub const MAX_PRD_PAYLOAD_SIZE: usize = u16::MAX as usize; // 64KiB sounds reasonable for now
pub trait MutexExt<T> {
fn lock_anyhow(&self) -> Result<MutexGuard<T>, anyhow::Error>;
}
impl<T: Debug> MutexExt<T> for Mutex<T> {
fn lock_anyhow(&self) -> Result<MutexGuard<T>, anyhow::Error> {
self.lock()
.map_err(|e| anyhow::Error::msg(format!("Failed to lock: {}", e)))
}
}