Struct async_change_tracker::ChangeTracker

source ·
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.

Subscribe to changes by calling get_changes.

Note that this does not implement Clone because typically this is not what you want. Rather, you should wrap ChangeTracker in Arc<RwLock> or similar.

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.

Auto Trait Implementations§

§

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

§

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: Sync + Send,

§

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more