Crates.io | raii-change-tracker |
lib.rs | raii-change-tracker |
version | 0.1.1 |
source | src |
created_at | 2017-07-23 19:15:02.244137 |
updated_at | 2018-04-14 22:37:07.01598 |
description | tracks changes to data and notifies listeners |
homepage | |
repository | https://github.com/astraw/raii-change-tracker |
max_upload_size | |
id | 24728 |
size | 31,050 |
Documentation is available here.
Track changes to data and notify listeners.
The main API feature is the DataTracker
struct, which takes ownership of a value.
To listen for changes to an instance of the DataTracker
struct, the function
DataTracker::add_listener()
returns a futures::Stream
. This Stream
is
supplied with previous and new values immediately after each change and
integrates with the tokio ecosystem.
The principle of operation is that DataTracker::as_tracked_mut()
returns a
mutable Modifier
. Modifier
is a RAII scoped guard with two key properties:
DerefMut
trait to
allow ergonomic access to the underlying data.Drop
trait which checks if the underlying data was changed and, if so, notifies the
listeners.Futhermore, DataTracker::as_ref()
returns a (non-mutable) reference to the
data for cases when only read-only access to the data is needed.
To implement tracking, when Modifier
is created, a copy of the original data
is made and when Modifier
is dropped, an equality check is performed. If the
original and the new data are not equal, the callbacks are called with
references to the old and the new values.
Licensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Anyone who interacts with raii-change-tracker in any space including but not limited to this GitHub repository is expected to follow our code of conduct.