Struct Builder

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

Construct the settings around how a Refreshed should be created and updated.

Implementations§

Source§

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

Source

pub fn duration(&mut self, duration: Duration) -> &mut Self

Set the duration for refreshing. Default value: 60 seconds.

Source

pub fn error(&mut self, error: impl Fn(&E) + Send + Sync + 'static) -> &mut Self

What should we do with error values produced while refreshing? Default: no action.

Source

pub fn success( &mut self, success: impl Fn(&T) + Send + Sync + 'static, ) -> &mut Self

What should we do with success values produced while refreshing? Default: no action.

Source

pub fn exit(&mut self, exit: impl Fn() + Send + Sync + 'static) -> &mut Self

What should we do when the refresh loop exits? Default: debug level log message.

Source

pub async fn try_build<Fut, MkFut>( &self, mk_fut: MkFut, ) -> Result<Refreshed<T, E>, E>
where Fut: Future<Output = Result<T, E>> + Send + 'static, MkFut: FnMut(bool) -> Fut + Send + 'static,

Construct a Refreshed value from the given initialization function, which may fail.

The closure is provided false on the first call, and true on subsequent refresh calls.

Source§

impl<T> Builder<T, Infallible>
where T: Send + Sync + 'static,

Source

pub async fn build<Fut, MkFut>(&self, mk_fut: MkFut) -> Refreshed<T, Infallible>
where Fut: Future<Output = T> + Send + 'static, MkFut: FnMut(bool) -> Fut + Send + 'static,

Construct a Refreshed value from the given initialization function

Source§

impl<T, E> Builder<T, E>
where T: Send + Sync + 'static, E: Debug + Send + Sync + 'static,

Source

pub fn log_errors(&mut self) -> &mut Self

Turn on default error logging when an error occurs.

Trait Implementations§

Source§

impl<T, E> Default for Builder<T, E>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T, E> Freeze for Builder<T, E>

§

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

§

impl<T, E> Send for Builder<T, E>
where T: Send, E: Send,

§

impl<T, E> Sync for Builder<T, E>
where T: Sync, E: Sync,

§

impl<T, E> Unpin for Builder<T, E>
where T: Unpin, E: Unpin,

§

impl<T, E> !UnwindSafe for Builder<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.