#[cfg(feature = "std")]
pub(crate) use std::collections::HashMap;
#[cfg(not(feature = "std"))]
pub(crate) use hashbrown::HashMap;
#[cfg(feature = "std")]
mod lock {
use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
pub(crate) fn read_lock<T>(
lock: &RwLock<T>,
) -> Result<RwLockReadGuard<'_, T>, alloc::string::String> {
lock.read()
.map_err(|e| alloc::format!("RwLock poisoned: {e}"))
}
pub(crate) fn write_lock<T>(
lock: &RwLock<T>,
) -> Result<RwLockWriteGuard<'_, T>, alloc::string::String> {
lock.write()
.map_err(|e| alloc::format!("RwLock poisoned: {e}"))
}
}
#[cfg(not(feature = "std"))]
mod lock {
use spin::{RwLock, RwLockReadGuard, RwLockWriteGuard};
pub(crate) fn read_lock<T>(
lock: &RwLock<T>,
) -> Result<RwLockReadGuard<'_, T>, alloc::string::String> {
Result::<_, core::convert::Infallible>::Ok(lock.read()).map_err(|e| match e {})
}
pub(crate) fn write_lock<T>(
lock: &RwLock<T>,
) -> Result<RwLockWriteGuard<'_, T>, alloc::string::String> {
Result::<_, core::convert::Infallible>::Ok(lock.write()).map_err(|e| match e {})
}
}
#[cfg(feature = "std")]
pub(crate) use std::sync::RwLock;
pub(crate) use lock::{read_lock, write_lock};
#[cfg(not(feature = "std"))]
pub(crate) use spin::RwLock;