Struct data_tracker::DataTracker
[−]
[src]
pub struct DataTracker<T, K> where
T: Clone + PartialEq,
K: Hash + Eq, { /* fields omitted */ }
Tracks changes to data and notifies listeners.
The data to be tracked is type T
.
Callbacks are stored in a HashMap
with keys of type K
.
See the module-level documentation for more details.
Methods
impl<T, K> DataTracker<T, K> where
T: Clone + PartialEq,
K: Hash + Eq,
[src]
T: Clone + PartialEq,
K: Hash + Eq,
fn new(value: T) -> DataTracker<T, K>
Create a new DataTracker
which takes ownership
of the data of type T
.
Callbacks are registered via a key of type K
.
fn add_listener(
&mut self,
key: K,
callback: Box<OnChanged<T>>
) -> Option<Box<OnChanged<T>>>
&mut self,
key: K,
callback: Box<OnChanged<T>>
) -> Option<Box<OnChanged<T>>>
Add a callback that will be called just after a data change is detected.
If a previous callback exists with the key
, the original callback is
returned as Some(original_callback)
. Otherwise, None
is returned.
fn remove_listener(&mut self, key: &K) -> Option<Box<OnChanged<T>>>
Remove callback.
If a callback exists with the key
, it is removed and returned as
Some(callback)
. Otherwise, None
is returned.
fn as_tracked_mut(&mut self) -> Modifier<T, K>
Return a Modifier
which can be used to modify the owned data.
Trait Implementations
impl<T, K> AsRef<T> for DataTracker<T, K> where
T: Clone + PartialEq,
K: Hash + Eq,
[src]
T: Clone + PartialEq,
K: Hash + Eq,
fn as_ref(&self) -> &T
Performs the conversion.