pub struct Config { /* private fields */ }
Expand description
A structure storing all config items.
It contains a global table and multiple named tables, each table is a map
from key to value, the key is a string and the value is a ConfigItem
.
Implementations§
Source§impl Config
impl Config
Sourcepub const GLOBAL_TABLE_NAME: &'static str = "$GLOBAL"
pub const GLOBAL_TABLE_NAME: &'static str = "$GLOBAL"
The name of the global table of the config.
Sourcepub fn global_table(&self) -> &BTreeMap<String, ConfigItem>
pub fn global_table(&self) -> &BTreeMap<String, ConfigItem>
Returns the global table of the config.
Sourcepub fn table_at(&self, name: &str) -> Option<&BTreeMap<String, ConfigItem>>
pub fn table_at(&self, name: &str) -> Option<&BTreeMap<String, ConfigItem>>
Returns the reference to the table with the specified name.
Sourcepub fn table_at_mut(
&mut self,
name: &str,
) -> Option<&mut BTreeMap<String, ConfigItem>>
pub fn table_at_mut( &mut self, name: &str, ) -> Option<&mut BTreeMap<String, ConfigItem>>
Returns the mutable reference to the table with the specified name.
Sourcepub fn config_at(&self, table: &str, key: &str) -> Option<&ConfigItem>
pub fn config_at(&self, table: &str, key: &str) -> Option<&ConfigItem>
Returns the reference to the config item with the specified table name and key.
Sourcepub fn config_at_mut(
&mut self,
table: &str,
key: &str,
) -> Option<&mut ConfigItem>
pub fn config_at_mut( &mut self, table: &str, key: &str, ) -> Option<&mut ConfigItem>
Returns the mutable reference to the config item with the specified table name and key.
Sourcepub fn table_comments_at(&self, name: &str) -> Option<&str>
pub fn table_comments_at(&self, name: &str) -> Option<&str>
Returns the comments of the table with the specified name.
Sourcepub fn table_iter(
&self,
) -> impl Iterator<Item = (&str, &BTreeMap<String, ConfigItem>, &str)>
pub fn table_iter( &self, ) -> impl Iterator<Item = (&str, &BTreeMap<String, ConfigItem>, &str)>
Returns the iterator of all tables.
The iterator returns a tuple of table name, table and comments. The
global table is named $GLOBAL
.
Sourcepub fn iter(&self) -> impl Iterator<Item = &ConfigItem>
pub fn iter(&self) -> impl Iterator<Item = &ConfigItem>
Returns the iterator of all config items.
The iterator returns a tuple of table name, key and config item. The
global table is named $GLOBAL
.
Source§impl Config
impl Config
Sourcepub fn from_toml(toml: &str) -> ConfigResult<Self>
pub fn from_toml(toml: &str) -> ConfigResult<Self>
Parse a toml string into a config object.
Sourcepub fn dump(&self, fmt: OutputFormat) -> ConfigResult<String>
pub fn dump(&self, fmt: OutputFormat) -> ConfigResult<String>
Dump the config into a string with the specified format.
Sourcepub fn dump_toml(&self) -> ConfigResult<String>
pub fn dump_toml(&self) -> ConfigResult<String>
Dump the config into TOML format.
Sourcepub fn dump_rs(&self) -> ConfigResult<String>
pub fn dump_rs(&self) -> ConfigResult<String>
Dump the config into Rust code.
Sourcepub fn merge(&mut self, other: &Self) -> ConfigResult<()>
pub fn merge(&mut self, other: &Self) -> ConfigResult<()>
Merge the other config into self
, if there is a duplicate key, return an error.
Sourcepub fn update(
&mut self,
other: &Self,
) -> ConfigResult<(Vec<ConfigItem>, Vec<ConfigItem>)>
pub fn update( &mut self, other: &Self, ) -> ConfigResult<(Vec<ConfigItem>, Vec<ConfigItem>)>
Update the values of self
with the other config, if there is a key not
found in self
, skip it.
It returns two vectors of ConfigItem
, the first contains the keys that
are included in self
but not in other
, the second contains the keys
that are included in other
but not in self
.