pub struct ConfigData {
pub values: IndexMap<String, Value>,
pub sections: IndexMap<String, Vec<SectionEntry>>,
}Expand description
Represents hierarchical configuration data with support for logical sections.
Keys in the configuration are expected to be in a dotted format (e.g., arcella.log.level).
This struct allows grouping related keys into sections for easier access.
The underlying storage uses IndexMap to preserve the order of insertion for keys.
Fields§
§values: IndexMap<String, Value>Original flat map of all parameters, sorted by key.
sections: IndexMap<String, Vec<SectionEntry>>Map of sections (e.g., “arcella”, “arcella.log”, “arcella.modules”).
The value is a vector of SectionEntry items, representing
the next level keys that belong to this section.
For example, if the key is “arcella.log.level”, then only “arcella.log” sections will contain its index
Implementations§
Source§impl ConfigData
impl ConfigData
Sourcepub fn get(&self, key: &str) -> Option<&Value>
pub fn get(&self, key: &str) -> Option<&Value>
Retrieves a reference to the value associated with the given key.
§Arguments
key- The configuration key to look up.
§Returns
Some(&Value) if the key exists, otherwise None.
§Example
use arcella_types::config::{ConfigData, Value};
use indexmap::IndexMap;
let mut input = IndexMap::new();
input.insert("key1".to_string(), Value::Integer(42));
let config = ConfigData::new(input);
assert_eq!(config.get("key1"), Some(&Value::Integer(42)));
assert_eq!(config.get("nonexistent"), None);Sourcepub fn get_section_data(
&self,
section: &str,
) -> Option<IndexMap<String, &Value>>
pub fn get_section_data( &self, section: &str, ) -> Option<IndexMap<String, &Value>>
Retrieves the key-value pairs belonging to the specified section.
This method returns an IndexMap where keys are the full configuration keys
(e.g., “arcella.log.level”) and values are references to the corresponding Values.
The order of the returned map reflects the sorted order of the original keys.
§Arguments
section- The name of the configuration section (e.g., “arcella.log”).
§Returns
Some(IndexMap<String, &Value>) if the section exists, otherwise None.
§Example
use arcella_types::config::{ConfigData, Value};
use indexmap::IndexMap;
let mut input = IndexMap::new();
input.insert("arcella.log.level".to_string(), Value::String("info".to_string()));
input.insert("arcella.log.file".to_string(), Value::String("log.txt".to_string()));
input.insert("arcella.modules.path".to_string(), Value::String("/mods".to_string()));
let config = ConfigData::new(input);
let log_section = config.get_section_data("arcella.log").unwrap();
assert_eq!(log_section.len(), 2);
assert_eq!(log_section.get("arcella.log.level"), Some(&&Value::String("info".to_string())));
assert_eq!(log_section.get("arcella.log.file"), Some(&&Value::String("log.txt".to_string())));Trait Implementations§
Source§impl Clone for ConfigData
impl Clone for ConfigData
Source§fn clone(&self) -> ConfigData
fn clone(&self) -> ConfigData
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more