Struct Reloadable

Source
pub struct Reloadable<T, R> { /* private fields */ }
Expand description

A generic reloadable shared state.

Implementations§

Source§

impl<T, L> Reloadable<T, L>

Source

pub fn new(loader: L, initial_value: Arc<T>) -> Self

Create a new Reloadable with a specified initial value.

Source

pub fn get(&self) -> Arc<T>

Get the currently loaded value.

Source

pub fn set(&self, value: Arc<T>) -> Arc<T>

Store new value and return the old one.

Source§

impl<T, L> Reloadable<T, L>
where L: Loader<Value = T>,

Source

pub async fn init_load(loader: L) -> Result<(Self, Arc<T>), L::Error>

Load the initial value and create a new Reloadable.

Source

pub async fn reload(&self) -> Result<Arc<T>, L::Error>

Reload the value, store it and return the newly loaded value.

If loader fails with an error, the stored value doesn’t change.

Trait Implementations§

Source§

impl<T, R> Debug for Reloadable<T, R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, R> !Freeze for Reloadable<T, R>

§

impl<T, R> !RefUnwindSafe for Reloadable<T, R>

§

impl<T, R> Send for Reloadable<T, R>
where R: Send, T: Sync + Send,

§

impl<T, R> Sync for Reloadable<T, R>
where R: Send, T: Sync + Send,

§

impl<T, R> Unpin for Reloadable<T, R>
where R: Unpin,

§

impl<T, R> UnwindSafe for Reloadable<T, R>

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.