#[cfg(not(any(doc, target_arch = "riscv32")))]
mod _impl {
pub use core::cell::Cell as ContractCell;
}
#[cfg(all(not(any(doc, target_arch = "riscv32")), feature = "std"))]
mod _ref_impl {
pub use core::cell::RefCell as ContractRefCell;
impl<T: 'static> super::ContractLocalRef<T>
for std::thread::LocalKey<ContractRefCell<T>>
{
fn with_ref<R>(
&'static self,
f: impl FnOnce(&core::cell::RefCell<T>) -> R,
) -> R {
self.with(f)
}
}
}
#[cfg(all(any(doc, target_arch = "riscv32"), feature = "alloc"))]
mod _ref_impl {
pub struct ContractRefCell<T>(core::cell::RefCell<T>);
unsafe impl<T> Sync for ContractRefCell<T> {}
impl<T> ContractRefCell<T> {
pub const fn new(value: T) -> Self {
Self(core::cell::RefCell::new(value))
}
}
impl<T> super::ContractLocalRef<T> for ContractRefCell<T> {
fn with_ref<R>(
&'static self,
f: impl FnOnce(&core::cell::RefCell<T>) -> R,
) -> R {
f(&self.0)
}
}
}
#[cfg(feature = "alloc")]
#[allow(unused_imports)]
pub use _ref_impl::*;
#[cfg(feature = "alloc")]
pub(crate) trait ContractLocalRef<T> {
fn with_ref<R>(
&'static self,
f: impl FnOnce(&core::cell::RefCell<T>) -> R,
) -> R;
}
#[cfg(any(doc, target_arch = "riscv32"))]
mod _impl {
use core::ops::Deref;
pub struct ContractCell<T: ?Sized>(core::cell::Cell<T>);
unsafe impl<T: ?Sized> Sync for ContractCell<T> {}
impl<T: ?Sized> Deref for ContractCell<T> {
type Target = core::cell::Cell<T>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T> ContractCell<T> {
pub const fn new(value: T) -> Self {
Self(core::cell::Cell::new(value))
}
}
}
pub use _impl::*;