Trait zng_ext_config::ConfigMap
source · pub trait ConfigMap: VarValue + Debug {
// Required methods
fn empty() -> Self;
fn read(file: WatchFile) -> Result<Self>;
fn write(self, file: &mut WriteFile) -> Result<()>;
fn get_raw(
&self,
key: &ConfigKey,
) -> Result<Option<RawConfigValue>, Arc<dyn Error + Send + Sync>>;
fn set_raw(
map: &mut VarModify<'_, Self>,
key: ConfigKey,
value: RawConfigValue,
) -> Result<(), Arc<dyn Error + Send + Sync>>;
fn contains_key(&self, key: &ConfigKey) -> bool;
fn remove(map: &mut VarModify<'_, Self>, key: &ConfigKey);
// Provided methods
fn get<O: ConfigValue>(
&self,
key: &ConfigKey,
) -> Result<Option<O>, Arc<dyn Error + Send + Sync>> { ... }
fn set<O: ConfigValue>(
map: &mut VarModify<'_, Self>,
key: ConfigKey,
value: O,
) -> Result<(), Arc<dyn Error + Send + Sync>> { ... }
}
Expand description
Represents a full config map in memory.
This can be used with SyncConfig
to implement a full config.
Required Methods§
sourcefn read(file: WatchFile) -> Result<Self>
fn read(file: WatchFile) -> Result<Self>
Read a map from the file.
This method runs in unblocked context.
sourcefn write(self, file: &mut WriteFile) -> Result<()>
fn write(self, file: &mut WriteFile) -> Result<()>
Write the map to a file.
This method runs in unblocked context.
sourcefn get_raw(
&self,
key: &ConfigKey,
) -> Result<Option<RawConfigValue>, Arc<dyn Error + Send + Sync>>
fn get_raw( &self, key: &ConfigKey, ) -> Result<Option<RawConfigValue>, Arc<dyn Error + Send + Sync>>
Gets the weak typed value.
This method is used when T
cannot be passed because the map is behind a dynamic reference,
the backend must convert the value from the in memory representation to RawConfigValue
.
This method can run in blocking contexts, work with in memory storage only.
sourcefn set_raw(
map: &mut VarModify<'_, Self>,
key: ConfigKey,
value: RawConfigValue,
) -> Result<(), Arc<dyn Error + Send + Sync>>
fn set_raw( map: &mut VarModify<'_, Self>, key: ConfigKey, value: RawConfigValue, ) -> Result<(), Arc<dyn Error + Send + Sync>>
Sets the weak typed value.
This method is used when T
cannot be passed because the map is behind a dynamic reference,
the backend must convert to the in memory representation.
If map
is dereferenced mutable a write task will, if possible check if the entry already has the same value
before mutating the map to avoid a potentially expensive IO write.
This method can run in blocking contexts, work with in memory storage only.
sourcefn contains_key(&self, key: &ConfigKey) -> bool
fn contains_key(&self, key: &ConfigKey) -> bool
Returns if the key in config.
This method can run in blocking contexts, work with in memory storage only.
Provided Methods§
sourcefn get<O: ConfigValue>(
&self,
key: &ConfigKey,
) -> Result<Option<O>, Arc<dyn Error + Send + Sync>>
fn get<O: ConfigValue>( &self, key: &ConfigKey, ) -> Result<Option<O>, Arc<dyn Error + Send + Sync>>
Get the value if present.
This method can run in blocking contexts, work with in memory storage only.
sourcefn set<O: ConfigValue>(
map: &mut VarModify<'_, Self>,
key: ConfigKey,
value: O,
) -> Result<(), Arc<dyn Error + Send + Sync>>
fn set<O: ConfigValue>( map: &mut VarModify<'_, Self>, key: ConfigKey, value: O, ) -> Result<(), Arc<dyn Error + Send + Sync>>
Set the value.
If possible check if the entry already has the same value before mutating the map to avoid a potentially expensive clone operation. Note that the map will only be written if the map actually changes, or an update is explicitly requested.
This method can run in blocking contexts, work with in memory storage only.