34 lines
881 B
Rust
34 lines
881 B
Rust
#![allow(warnings)]
|
|
use anyhow::Error;
|
|
use sdk_common::crypto::AnkSharedSecret;
|
|
use sdk_common::network::CachedMessage;
|
|
use serde::{Deserialize, Serialize};
|
|
use std::collections::{HashMap, HashSet};
|
|
use std::fmt::Debug;
|
|
use std::sync::{Mutex, MutexGuard, OnceLock};
|
|
use tsify::Tsify;
|
|
|
|
pub mod api;
|
|
mod peers;
|
|
mod user;
|
|
mod wallet;
|
|
|
|
pub static CACHEDMESSAGES: OnceLock<Mutex<Vec<CachedMessage>>> = OnceLock::new();
|
|
|
|
pub fn lock_messages() -> Result<MutexGuard<'static, Vec<CachedMessage>>, Error> {
|
|
CACHEDMESSAGES
|
|
.get_or_init(|| Mutex::new(vec![]))
|
|
.lock_anyhow()
|
|
}
|
|
|
|
pub(crate) trait MutexExt<T> {
|
|
fn lock_anyhow(&self) -> Result<MutexGuard<T>, Error>;
|
|
}
|
|
|
|
impl<T: Debug> MutexExt<T> for Mutex<T> {
|
|
fn lock_anyhow(&self) -> Result<MutexGuard<T>, Error> {
|
|
self.lock()
|
|
.map_err(|e| Error::msg(format!("Failed to lock: {}", e)))
|
|
}
|
|
}
|