#![allow(unused_imports)]
#[cfg(not(feature = "std"))]
pub use alloc::{
boxed::Box,
format,
string::{String, ToString},
vec,
vec::Vec,
};
#[cfg(feature = "std")]
pub use std::{
boxed::Box,
format,
string::{String, ToString},
vec,
vec::Vec,
};
#[cfg(not(feature = "std"))]
pub use alloc::collections::{BTreeMap as HashMap, BTreeSet as HashSet};
#[cfg(feature = "std")]
pub use std::collections::{HashMap, HashSet};
#[cfg(not(feature = "std"))]
pub use alloc::sync::{Arc, Weak};
#[cfg(feature = "std")]
pub use std::sync::{Arc, Weak};
#[cfg(not(feature = "std"))]
pub use spin::{Mutex, RwLock};
#[cfg(feature = "std")]
pub use std::sync::{Mutex, RwLock};
#[cfg(not(feature = "std"))]
pub use core::{
cell::{Cell, RefCell},
fmt,
hash::{Hash, Hasher},
ops,
};
#[cfg(feature = "std")]
pub use std::{
cell::{Cell, RefCell},
fmt,
hash::{Hash, Hasher},
ops,
};
#[cfg(not(feature = "std"))]
pub use spin::Lazy;
#[cfg(feature = "std")]
pub use std::sync::LazyLock as Lazy;
pub struct RwLockGuard<T>(T);
impl<T> core::ops::Deref for RwLockGuard<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T> core::ops::DerefMut for RwLockGuard<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
pub trait RwLockExt<T> {
fn read_compat(&self) -> Result<RwLockGuard<impl core::ops::Deref<Target = T> + '_>, String>;
fn write_compat(&self) -> Result<RwLockGuard<impl core::ops::DerefMut<Target = T> + '_>, String>;
}
#[cfg(feature = "std")]
impl<T> RwLockExt<T> for RwLock<T> {
fn read_compat(&self) -> Result<RwLockGuard<impl core::ops::Deref<Target = T> + '_>, String> {
self.read().map(RwLockGuard).map_err(|e| format!("{:?}", e))
}
fn write_compat(&self) -> Result<RwLockGuard<impl core::ops::DerefMut<Target = T> + '_>, String> {
self.write().map(RwLockGuard).map_err(|e| format!("{:?}", e))
}
}
#[cfg(not(feature = "std"))]
impl<T> RwLockExt<T> for RwLock<T> {
fn read_compat(&self) -> Result<RwLockGuard<impl core::ops::Deref<Target = T> + '_>, String> {
Ok(RwLockGuard(self.read()))
}
fn write_compat(&self) -> Result<RwLockGuard<impl core::ops::DerefMut<Target = T> + '_>, String> {
Ok(RwLockGuard(self.write()))
}
}