[−][src]Struct refreshable::Refreshable
A wrapper around a live-refreshable value.
Implementations
impl<T, E> Refreshable<T, E> where
T: PartialEq + 'static + Sync + Send,
E: 'static,
[src]
T: PartialEq + 'static + Sync + Send,
E: 'static,
pub fn new(value: T) -> (Refreshable<T, E>, RefreshHandle<T, E>)
[src]
Creates a new Refreshable
with an initial value, returning it along with a RefreshHandle
used to update it
with new values.
pub fn get(&self) -> Guard<'_, T>
[src]
Returns a guard type providing access to a snapshot of the refreshable's current value.
pub fn subscribe<F>(&self, callback: F) -> Result<Subscription<T, E>, E> where
F: Fn(&T) -> Result<(), E> + 'static + Sync + Send,
[src]
F: Fn(&T) -> Result<(), E> + 'static + Sync + Send,
Subscribes to the refreshable.
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.
pub fn subscribe_ok<F>(&self, callback: F) -> Subscription<T, E> where
F: Fn(&T) + 'static + Sync + Send,
[src]
F: Fn(&T) + 'static + Sync + Send,
Subscribes to the refreshable with an infallible callback.
This is a convenience method to simplify subscription when the callback can never fail.
pub fn map<F, R>(&self, map: F) -> Refreshable<R, E> where
F: Fn(&T) -> R + 'static + Sync + Send,
R: PartialEq + 'static + Sync + Send,
[src]
F: Fn(&T) -> R + 'static + Sync + Send,
R: PartialEq + 'static + Sync + Send,
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.
Auto Trait Implementations
impl<T, E> !RefUnwindSafe for Refreshable<T, E>
[src]
impl<T, E> Send for Refreshable<T, E> where
T: Send + Sync,
[src]
T: Send + Sync,
impl<T, E> Sync for Refreshable<T, E> where
T: Send + Sync,
[src]
T: Send + Sync,
impl<T, E> Unpin for Refreshable<T, E>
[src]
impl<T, E> !UnwindSafe for Refreshable<T, E>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,