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§

source

fn empty() -> Self

New empty map.

source

fn read(file: WatchFile) -> Result<Self>

Read a map from the file.

This method runs in unblocked context.

source

fn write(self, file: &mut WriteFile) -> Result<()>

Write the map to a file.

This method runs in unblocked context.

source

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.

source

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.

source

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.

source

fn remove(map: &mut VarModify<'_, Self>, key: &ConfigKey)

Remove the config entry associated with the key.

Provided Methods§

source

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.

source

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl ConfigMap for IndexMap<ConfigKey, Value>

source§

fn empty() -> Self

source§

fn read(file: WatchFile) -> Result<Self>

source§

fn write(self, file: &mut WriteFile) -> Result<()>

source§

fn get_raw( &self, key: &ConfigKey, ) -> Result<Option<RawConfigValue>, Arc<dyn Error + Send + Sync>>

source§

fn set_raw( map: &mut VarModify<'_, Self>, key: ConfigKey, value: RawConfigValue, ) -> Result<(), Arc<dyn Error + Send + Sync>>

source§

fn contains_key(&self, key: &ConfigKey) -> bool

source§

fn get<O: ConfigValue>( &self, key: &ConfigKey, ) -> Result<Option<O>, Arc<dyn Error + Send + Sync>>

source§

fn set<O: ConfigValue>( map: &mut VarModify<'_, Self>, key: ConfigKey, value: O, ) -> Result<(), Arc<dyn Error + Send + Sync>>

source§

fn remove(map: &mut VarModify<'_, Self>, key: &ConfigKey)

source§

impl ConfigMap for IndexMap<ConfigKey, Value>

source§

fn empty() -> Self

source§

fn read(file: WatchFile) -> Result<Self>

source§

fn write(self, file: &mut WriteFile) -> Result<()>

source§

fn get_raw( &self, key: &ConfigKey, ) -> Result<Option<RawConfigValue>, Arc<dyn Error + Send + Sync>>

source§

fn set_raw( map: &mut VarModify<'_, Self>, key: ConfigKey, value: RawConfigValue, ) -> Result<(), Arc<dyn Error + Send + Sync>>

source§

fn contains_key(&self, key: &ConfigKey) -> bool

source§

fn get<O: ConfigValue>( &self, key: &ConfigKey, ) -> Result<Option<O>, Arc<dyn Error + Send + Sync>>

source§

fn set<O: ConfigValue>( map: &mut VarModify<'_, Self>, key: ConfigKey, value: O, ) -> Result<(), Arc<dyn Error + Send + Sync>>

source§

fn remove(map: &mut VarModify<'_, Self>, key: &ConfigKey)

source§

impl ConfigMap for IndexMap<ConfigKey, Value>

source§

fn empty() -> Self

source§

fn read(file: WatchFile) -> Result<Self>

source§

fn write(self, file: &mut WriteFile) -> Result<()>

source§

fn get_raw( &self, key: &ConfigKey, ) -> Result<Option<RawConfigValue>, Arc<dyn Error + Send + Sync>>

source§

fn set_raw( map: &mut VarModify<'_, Self>, key: ConfigKey, value: RawConfigValue, ) -> Result<(), Arc<dyn Error + Send + Sync>>

source§

fn contains_key(&self, key: &ConfigKey) -> bool

source§

fn get<O: ConfigValue>( &self, key: &ConfigKey, ) -> Result<Option<O>, Arc<dyn Error + Send + Sync>>

source§

fn set<O: ConfigValue>( map: &mut VarModify<'_, Self>, key: ConfigKey, value: O, ) -> Result<(), Arc<dyn Error + Send + Sync>>

source§

fn remove(map: &mut VarModify<'_, Self>, key: &ConfigKey)

source§

impl ConfigMap for IndexMap<ConfigKey, Value>

source§

fn empty() -> Self

source§

fn read(file: WatchFile) -> Result<Self>

source§

fn write(self, file: &mut WriteFile) -> Result<()>

source§

fn get_raw( &self, key: &ConfigKey, ) -> Result<Option<RawConfigValue>, Arc<dyn Error + Send + Sync>>

source§

fn set_raw( map: &mut VarModify<'_, Self>, key: ConfigKey, value: RawConfigValue, ) -> Result<(), Arc<dyn Error + Send + Sync>>

source§

fn contains_key(&self, key: &ConfigKey) -> bool

source§

fn get<O: ConfigValue>( &self, key: &ConfigKey, ) -> Result<Option<O>, Arc<dyn Error + Send + Sync>>

source§

fn set<O: ConfigValue>( map: &mut VarModify<'_, Self>, key: ConfigKey, value: O, ) -> Result<(), Arc<dyn Error + Send + Sync>>

source§

fn remove(map: &mut VarModify<'_, Self>, key: &ConfigKey)

Implementors§