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:
- If cache hit, return the cached value when reading, while update the cached value and then write back when writing.
- 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
impl Config
sourcepub fn get<T>(&self) -> ConfigRef<'_, T>
pub fn get<T>(&self) -> ConfigRef<'_, T>
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.
sourcepub fn get_mut<T>(&self) -> ConfigMut<'_, T>
pub fn get_mut<T>(&self) -> ConfigMut<'_, T>
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.
sourcepub fn take<T>(&self) -> T
pub fn take<T>(&self) -> T
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.
sourcepub fn get_many<T>(&self) -> <T as Cacheable<((),)>>::Ref<'_>
pub fn get_many<T>(&self) -> <T as Cacheable<((),)>>::Ref<'_>
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.
sourcepub fn get_mut_many<T>(&self) -> <T as Cacheable<((),)>>::Mut<'_>
pub fn get_mut_many<T>(&self) -> <T as Cacheable<((),)>>::Mut<'_>
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.
sourcepub fn take_many<T>(&self) -> <T as Cacheable<((),)>>::Owned
pub fn take_many<T>(&self) -> <T as Cacheable<((),)>>::Owned
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.
sourcepub fn save<T>(&self, value: T) -> ConfigResult<()>
pub fn save<T>(&self, value: T) -> ConfigResult<()>
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.