From 3cbe77c143f271fa9dfddec3a6a9e0e9219c483a Mon Sep 17 00:00:00 2001 From: Sosthene Date: Mon, 23 Sep 2024 12:43:56 +0200 Subject: [PATCH] Add MutexExt trait --- src/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index f1b0d88..82316b7 100644 --- a/src/lib.rs +++ b/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 { + fn lock_anyhow(&self) -> Result, anyhow::Error>; +} + +impl MutexExt for Mutex { + fn lock_anyhow(&self) -> Result, anyhow::Error> { + self.lock() + .map_err(|e| anyhow::Error::msg(format!("Failed to lock: {}", e))) + } +}