ConfigData

Struct ConfigData 

Source
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

Source

pub fn new(values: IndexMap<String, Value>) -> Self

Creates a new ConfigData instance from a flat map of key-value pairs. It organizes the keys into hierarchical sections based on dot-separated prefixes.

§Arguments
  • values - An IndexMap containing the configuration keys and their values.
§Returns

A new ConfigData instance with organized sections.

Source

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);
Source

pub fn get_section_keys(&self, section: &str) -> Option<Vec<usize>>

Retrieves the indices of value keys belonging to the specified section.

§Arguments
  • section - The name of the configuration section (e.g., “arcella.log”).
§Returns

Some(Vec<usize>) containing the indices if the section exists, otherwise None.

Source

pub fn get_subsection_names(&self, section: &str) -> Option<Vec<String>>

Retrieves the names of sub-sections belonging to the specified section.

§Arguments
  • section - The name of the configuration section (e.g., “arcella.log”).
§Returns

Some(Vec<String>) containing the names of sub-sections if the section exists, otherwise None.

Source

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

Source§

fn clone(&self) -> ConfigData

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ConfigData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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

Source§

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.