Enum tomllib::types::Children
[−]
[src]
pub enum Children {
Count(Cell<usize>),
Keys(RefCell<Vec<String>>),
}Represents the child keys of a key in a parsed TOML document.
Variants
Count(Cell<usize>)Contains a Cell<usize> with the amount of child keys the key has. The key has children that are indexed with an
integer starting at 0. Arrays and array of tables use integer for their child keys. For example:
Array = ["A", "B", "C", "D", "E"]
[[array_of_table]]
key = "val 1"
[[array_of_table]]
key = "val 2"
[[array_of_table]]
key = "val 3"
"Array" has 5 children. The key of "D" is "Array[3]" because it is fourth element in "Array" and indexing starts at 0. "array_of_table" has 3 children. The key of "val 3" is "array_of_table[2].key" because it is in the third sub-table of "array_of_table" and indexing starts at 0.
Keys(RefCell<Vec<String>>)Contains a RefCell<Vec> of Strings with every sub-key of the key. The key has children that are indexed with a
sub-key. Tables and inline-tables use sub-keys for their child keys. For example:
InlineTable = {subkey1 = "A", subkey2 = "B"}
[table]
a_key = "val 1"
b_key = "val 2"
c_key = "val 3"
"InlineTable" has 2 children, "subkey1" and "subkey2". The key of "B" is "InlineTable.subkey2". "table" has 3 children, "a_key", "b_key", and "c_key". The key of "val 3" is "table.c_key".
Methods
impl Children[src]
Contains convenience functions to combine base keys with child keys to make a full key.
fn combine_keys<S>(base_key: S, child_key: S) -> String where S: Into<String>
Combines string type base_key with a string type child_key to form a full key.
Examples
use tomllib::TOMLParser; use tomllib::types::Children; let toml_doc = r#" [dependencies] nom = {version = "^1.2.0", features = ["regexp"]} regex = {version = "^0.1.48"} log = {version = "^0.3.5"} "#; let parser = TOMLParser::new(); let (parser, result) = parser.parse(toml_doc); let deps = parser.get_children("dependencies"); if let &Children::Keys(ref subkeys) = deps.unwrap() { assert_eq!("dependencies.nom", Children::combine_keys("dependencies", &subkeys.borrow()[0])); }
fn combine_keys_index<S>(base_key: S, child_key: usize) -> String where S: Into<String>
Combines string type base_key with an integer type child_key to form a full key.
Examples
use tomllib::TOMLParser; use tomllib::types::Children; let toml_doc = r#" keywords = ["toml", "parser", "encode", "decode", "nom"] "#; let parser = TOMLParser::new(); let (parser, result) = parser.parse(toml_doc); let kw = parser.get_children("keywords"); if let &Children::Count(ref subkeys) = kw.unwrap() { assert_eq!("keywords[4]", Children::combine_keys_index("keywords", subkeys.get() - 1)); }
fn combine_child_keys<S>(&self, base_key: S) -> Vec<String> where S: Into<String>
Combines string type base_key with all subkeys of an instance of Children to form a Vec of full keys
Examples
use tomllib::TOMLParser; use tomllib::types::Children; let toml_doc = r#" keywords = ["toml", "parser"] numbers = {first = 1, second = 2} "#; let parser = TOMLParser::new(); let (parser, result) = parser.parse(toml_doc); let kw = parser.get_children("keywords"); assert_eq!(vec!["keywords[0]".to_string(), "keywords[1]".to_string()], kw.unwrap().combine_child_keys("keywords")); let num = parser.get_children("numbers"); assert_eq!(vec!["numbers.first".to_string(), "numbers.second".to_string()], num.unwrap().combine_child_keys("numbers"));
Trait Implementations
impl Clone for Children[src]
fn clone(&self) -> Children
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0
Performs copy-assignment from source. Read more
impl PartialEq for Children[src]
fn eq(&self, __arg_0: &Children) -> bool
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, __arg_0: &Children) -> bool
This method tests for !=.