pub trait ShareValue {
type Value;
fn is_shared(&self) -> bool;
#[inline]
fn get(&self) -> Self::Value
where
Self::Value: Copy,
{
self.map(|v| *v)
}
#[inline]
fn get_cloned(&self) -> Self::Value
where
Self::Value: Clone,
{
self.map(<_>::clone)
}
#[inline]
fn set(&self, new_value: Self::Value) {
self.replace(new_value);
}
#[inline]
fn replace(&self, new_value: Self::Value) -> Self::Value {
self.replace_mut(|_| new_value)
}
#[inline]
fn replace_mut<F: FnOnce(&mut Self::Value) -> Self::Value>(&self, f: F) -> Self::Value {
self.map_mut(|old| {
let new_value = f(old);
std::mem::replace(old, new_value)
})
}
#[inline]
fn replace_with<F: FnOnce(&Self::Value) -> Self::Value>(&self, f: F) -> Self::Value {
self.replace_mut(move |v| f(v))
}
fn map<R>(&self, f: impl FnOnce(&Self::Value) -> R) -> R;
fn map_mut<R>(&self, f: impl FnOnce(&mut Self::Value) -> R) -> R;
fn equivalent_to(&self, other: &Self) -> bool;
}