pub struct ChangeTracker<T> { /* private fields */ }
Expand description

Tracks changes to data. Notifies listeners via a futures::Stream.

The data to be tracked is type T. The value of type T is wrapped in a private field. The AsRef trait is implemented so &T can be obtained by calling as_ref(). Read and write access can be gained by calling the modify method.

Subsribe to changes by calling get_changes.

See the module-level documentation for more information and a usage example.

Implementations§

source§

impl<T> ChangeTracker<T>
where T: Clone,

source

pub fn new(value: T) -> Self

Create a new ChangeTracker which takes ownership of the data of type T.

source

pub fn get_changes(&self, capacity: usize) -> Receiver<(T, T)>

Returns a futures::Stream that emits a message when a change occurs

The capacity of the underlying channel is specified with the capacity argument.

To remove a listener, drop the Receiver.

source

pub fn modify<F>(&mut self, f: F)
where F: FnOnce(&mut T),

Modify the data value, notifying listeners upon change.

Trait Implementations§

source§

impl<T> AsRef<T> for ChangeTracker<T>

source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T> Clone for ChangeTracker<T>
where T: Clone,

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for ChangeTracker<T>
where T: RefUnwindSafe,

§

impl<T> Send for ChangeTracker<T>
where T: Send,

§

impl<T> Sync for ChangeTracker<T>
where T: Send + Sync,

§

impl<T> Unpin for ChangeTracker<T>
where T: Unpin,

§

impl<T> UnwindSafe for ChangeTracker<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.