Struct Config

Source
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

Source

pub const GLOBAL_TABLE_NAME: &'static str = "$GLOBAL"

The name of the global table of the config.

Source

pub fn new() -> Self

Create a new empty config object.

Source

pub fn is_empty(&self) -> bool

Returns whether the config object contains no items.

Source

pub fn global_table(&self) -> &BTreeMap<String, ConfigItem>

Returns the global table of the config.

Source

pub fn table_at(&self, name: &str) -> Option<&BTreeMap<String, ConfigItem>>

Returns the reference to the table with the specified name.

Source

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.

Source

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.

Source

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.

Source

pub fn table_comments_at(&self, name: &str) -> Option<&str>

Returns the comments of the table with the specified name.

Source

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.

Source

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

Source

pub fn from_toml(toml: &str) -> ConfigResult<Self>

Parse a toml string into a config object.

Source

pub fn dump(&self, fmt: OutputFormat) -> ConfigResult<String>

Dump the config into a string with the specified format.

Source

pub fn dump_toml(&self) -> ConfigResult<String>

Dump the config into TOML format.

Source

pub fn dump_rs(&self) -> ConfigResult<String>

Dump the config into Rust code.

Source

pub fn merge(&mut self, other: &Self) -> ConfigResult<()>

Merge the other config into self, if there is a duplicate key, return an error.

Source

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.

Trait Implementations§

Source§

impl Debug for Config

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Config

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

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