Struct encrypt_config::config::Config

source ·
pub struct Config { /* private fields */ }
Expand description

A struct that can be used to cache configuration values. This behaves like a native cache in CPU:

  1. If cache hit, return the cached value when reading, while update the cached value and then write back when writing.
  2. If cache miss, load the cached value from the source to cache when reading, while write and then load when writing.

To avoid entering the password during testing, you can enable mock feature. This can always return the same Encrypter during each test.

Implementations§

source§

impl Config

source

pub fn new() -> Self

Create a new Config cache.

source

pub fn get<T>(&self) -> ConfigRef<'_, T>
where T: Source + Any + Send + Sync,

Get an immutable ref from the config. If the value is not found, it will be created with the default value. See ConfigRef for more details.

source

pub fn get_mut<T>(&self) -> ConfigMut<'_, T>
where T: Source + Any + Send + Sync,

Get a mutable ref from the config. If the value is not found, it will be created with the default value. See ConfigMut for more details.

source

pub fn take<T>(&self) -> T
where T: Source + Any + Send + Sync,

Take the ownership of the config value. If the value is not found, it will be created with the default value. This will remove the value from the config.

source

pub fn get_many<T>(&self) -> <T as Cacheable<((),)>>::Ref<'_>
where T: Cacheable<((),)> + Any + Send + Sync,

Get many immutable refs from the config.

T: (T1, T2, T3,)

If the value is not found, it will be created with the default value. See ConfigRef for more details.

source

pub fn get_mut_many<T>(&self) -> <T as Cacheable<((),)>>::Mut<'_>
where T: Cacheable<((),)> + Any + Send + Sync,

Get many mutable refs from the config.

T: (T1, T2, T3,)

If the value is not found, it will be created with the default value. See ConfigMut for more details.

source

pub fn take_many<T>(&self) -> <T as Cacheable<((),)>>::Owned
where T: Cacheable<((),)> + Any + Send + Sync,

Take the ownerships of the config value.

T: (T1, T2, T3,)

If the value is not found, it will be created with the default value. This will remove the value from the config.

source

pub fn save<T>(&self, value: T) -> ConfigResult<()>
where T: Source + Any + Send + Sync,

Save the config value manually. Note that the changes you made through ConfigMut will be saved as leaving the scope automatically.

Ideally, it’s better to change cache first and then set dirty flag when writing, and save the value when the cache drops. However, this is hard to implement for manual saving by now. So, one is supposed to use get and get_mut to change the value.

Trait Implementations§

source§

impl Default for Config

source§

fn default() -> Self

Create an empty Config cache.

Auto Trait Implementations§

§

impl !Freeze for Config

§

impl !RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

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> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V