Refreshable

Struct Refreshable 

Source
pub struct Refreshable<T, E> { /* private fields */ }
Expand description

A wrapper around a live-refreshable value.

Implementations§

Source§

impl<T, E> Refreshable<T, E>
where T: PartialEq + 'static + Sync + Send, E: 'static,

Source

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.

Source

pub fn get(&self) -> Guard<'_, T>

Returns a guard type providing access to a snapshot of the refreshable’s current value.

Source

pub fn subscribe<F>(&self, callback: F) -> Subscription<T, E>
where F: FnMut(&T) + 'static + Sync + Send,

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.

Source

pub fn try_subscribe<F>(&self, callback: F) -> Result<Subscription<T, E>, E>
where F: FnMut(&T) -> Result<(), E> + 'static + Sync + Send,

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.

Source

pub fn map<F, R>(&self, map: F) -> Refreshable<R, E>
where F: FnMut(&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.

Source

pub fn try_map<F, R>(&self, map: F) -> Result<Refreshable<R, E>, E>
where F: FnMut(&T) -> Result<R, E> + 'static + Sync + Send, R: PartialEq + 'static + Sync + Send,

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.

Auto Trait Implementations§

§

impl<T, E> !Freeze for Refreshable<T, E>

§

impl<T, E> !RefUnwindSafe for Refreshable<T, E>

§

impl<T, E> Send for Refreshable<T, E>
where T: Sync + Send,

§

impl<T, E> Sync for Refreshable<T, E>
where T: Sync + Send,

§

impl<T, E> Unpin for Refreshable<T, E>

§

impl<T, E> !UnwindSafe for Refreshable<T, E>

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.