use crate::bindref::*;
use crate::map_binding::*;
use std::sync::*;
pub trait Notifiable : Sync+Send {
fn mark_as_changed(&self);
}
pub trait Releasable : Send {
fn keep_alive(&mut self);
fn done(&mut self);
}
pub trait Changeable {
fn when_changed(&self, what: Arc<dyn Notifiable>) -> Box<dyn Releasable>;
}
pub trait Bound : Changeable + Send + Sync {
type Value;
fn get(&self) -> Self::Value;
fn watch(&self, what: Arc<dyn Notifiable>) -> Arc<dyn Watcher<Self::Value>>;
}
pub trait WithBound<Value>: Changeable + Send + Sync {
fn with_ref<F, T>(&self, f: F) -> T
where
F: FnOnce(&Value) -> T;
fn with_mut<F>(&self, f: F)
where
F: FnOnce(&mut Value) -> bool;
}
pub trait MutableBound : Bound {
fn set(&self, new_value: Self::Value);
}
pub trait Watcher<TValue> {
fn get(&self) -> TValue;
}
pub trait BoundValueComputeExt : Sized {
fn compute<TResultValue, TComputeFn>(&self, map_fn: TComputeFn) -> BindRef<TResultValue>
where
TResultValue: 'static + Clone + Send,
TComputeFn: 'static + Send + Sync + Fn(&Self) -> TResultValue;
}
pub trait BoundValueMapExt {
type Value;
fn map_binding<TMapValue, TMapFn>(&self, map_fn: TMapFn) -> MapBinding<Self, TMapValue, TMapFn>
where
TMapValue: 'static + Clone + Send,
TMapFn: 'static + Send + Sync + Fn(Self::Value) -> TMapValue;
}