use crate::RegionLocal;
pub trait RegionLocalExt<T> {
fn with_local<F, R>(&self, f: F) -> R
where
F: FnOnce(&T) -> R;
fn set_local(&self, value: T);
}
pub trait RegionLocalCopyExt<T>
where
T: Copy,
{
fn get_local(&self) -> T;
}
impl<T> RegionLocalExt<T> for linked::StaticInstancePerThread<RegionLocal<T>>
where
T: Clone + Send + Sync + 'static,
{
#[inline]
fn with_local<F, R>(&self, f: F) -> R
where
F: FnOnce(&T) -> R,
{
self.with(|inner| inner.with_local(f))
}
#[inline]
fn set_local(&self, value: T) {
self.with(|inner| inner.set_local(value));
}
}
impl<T> RegionLocalCopyExt<T> for linked::StaticInstancePerThread<RegionLocal<T>>
where
T: Clone + Copy + Send + Sync + 'static,
{
#[inline]
fn get_local(&self) -> T {
self.with(|inner| inner.get_local())
}
}