pub struct Refreshable<T, E> { /* private fields */ }Expand description
A wrapper around a live-refreshable value.
Implementations§
Source§impl<T, E> Refreshable<T, E>
impl<T, E> Refreshable<T, E>
Sourcepub fn new(value: T) -> (Refreshable<T, E>, RefreshHandle<T, E>)
pub fn new(value: T) -> (Refreshable<T, E>, RefreshHandle<T, E>)
Creates a new Refreshable with an initial value, returning it along with a RefreshHandle used to update it
with new values.
Sourcepub fn get(&self) -> Guard<'_, T>
pub fn get(&self) -> Guard<'_, T>
Returns a guard type providing access to a snapshot of the refreshable’s current value.
Sourcepub fn subscribe<F>(&self, callback: F) -> Subscription<T, E>
pub fn subscribe<F>(&self, callback: F) -> Subscription<T, E>
Subscribes to the refreshable with an infallible callback.
The callback will be invoked every time the refreshable’s value changes, and is also called synchronously when this method is called with the current value.
Sourcepub fn try_subscribe<F>(&self, callback: F) -> Result<Subscription<T, E>, E>
pub fn try_subscribe<F>(&self, callback: F) -> Result<Subscription<T, E>, E>
Subscribes to the refreshable with a fallible callback.
The callback will be invoked every time the refreshable’s value changes, and is also called synchronously when
this method is called with the current value. If the callback returns Ok, a Subscription object is returned
that will unsubscribe from the refreshable when it drops. If the callback returns Err, this method will return
the error and the callback will not be invoked on updates to the value. Errors in subsequent invocations will
be propagated to the originating RefreshHandle::refresh call.
Sourcepub fn map<F, R>(&self, map: F) -> Refreshable<R, E>
pub fn map<F, R>(&self, map: F) -> Refreshable<R, E>
Creates a new refreshable from this one by applying a mapping function to the value.
This can be used to narrow the scope of the refreshable value. Updates to the initial refreshable value will propagate to the mapped refreshable value, but the mapped refreshable’s subscriptions will only be invoked if the mapped value actually changed.
Sourcepub fn try_map<F, R>(&self, map: F) -> Result<Refreshable<R, E>, E>
pub fn try_map<F, R>(&self, map: F) -> Result<Refreshable<R, E>, E>
Creates a new refreshable from this one by applying a fallible mapping function to the value.
This can be used to narrow the scope of the refreshable value. Updates to the initial refreshable value will propagate to the mapped refreshable value, but the mapped refreshable’s subscriptions will only be invoked if the mapped value actually changed.