Add MutexExt trait
This commit is contained in:
parent
97df8ea13d
commit
3cbe77c143
17
src/lib.rs
17
src/lib.rs
@ -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)))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user