pub enum ConfigNodeValue {
Text(String),
Node(ConfigNode),
}Expand description
Represents the value of a ConfigNode key
Variants§
Text(String)
Any value that is not a new node. Numbers, lists, and other types of values are not parsed and are represented as their original textual form as this type.
Node(ConfigNode)
A new node
Implementations§
Source§impl ConfigNodeValue
impl ConfigNodeValue
Sourcepub fn as_text(&self) -> Option<&str>
pub fn as_text(&self) -> Option<&str>
Returns a reference to the inner tring of the ConfigNodeValue enum if self is of type ConfigNodeValue::Text,
otherwise None.
Examples found in repository?
examples/savefile.rs (line 9)
1fn main() {
2 let filename = std::env::args().nth(1).unwrap();
3 let savefile =
4 confignode::ConfigNodeParser::parse(&std::fs::read_to_string(filename).unwrap()).unwrap();
5 let game = savefile.children.get("GAME").unwrap().as_node().unwrap();
6
7 println!(
8 "Title: {}",
9 game.children.get("Title").unwrap().as_text().unwrap()
10 );
11 println!(
12 "Version: {}",
13 game.children.get("version").unwrap().as_text().unwrap()
14 );
15 println!(
16 "Version created: {}",
17 game.children
18 .get("versionCreated")
19 .unwrap()
20 .as_text()
21 .unwrap()
22 );
23}Sourcepub fn as_node(&self) -> Option<&ConfigNode>
pub fn as_node(&self) -> Option<&ConfigNode>
Returns a reference to the inner ConfigNode of the ConfigNodeValue enum if self is of type ConfigNodeValue::Node,
otherwise None.
Examples found in repository?
examples/savefile.rs (line 5)
1fn main() {
2 let filename = std::env::args().nth(1).unwrap();
3 let savefile =
4 confignode::ConfigNodeParser::parse(&std::fs::read_to_string(filename).unwrap()).unwrap();
5 let game = savefile.children.get("GAME").unwrap().as_node().unwrap();
6
7 println!(
8 "Title: {}",
9 game.children.get("Title").unwrap().as_text().unwrap()
10 );
11 println!(
12 "Version: {}",
13 game.children.get("version").unwrap().as_text().unwrap()
14 );
15 println!(
16 "Version created: {}",
17 game.children
18 .get("versionCreated")
19 .unwrap()
20 .as_text()
21 .unwrap()
22 );
23}Trait Implementations§
Source§impl Clone for ConfigNodeValue
impl Clone for ConfigNodeValue
Source§fn clone(&self) -> ConfigNodeValue
fn clone(&self) -> ConfigNodeValue
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ConfigNodeValue
impl Debug for ConfigNodeValue
Source§impl PartialEq for ConfigNodeValue
impl PartialEq for ConfigNodeValue
impl Eq for ConfigNodeValue
impl StructuralPartialEq for ConfigNodeValue
Auto Trait Implementations§
impl Freeze for ConfigNodeValue
impl RefUnwindSafe for ConfigNodeValue
impl Send for ConfigNodeValue
impl Sync for ConfigNodeValue
impl Unpin for ConfigNodeValue
impl UnwindSafe for ConfigNodeValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more