Enum yaml_rust::yaml::Yaml [] [src]

pub enum Yaml {
    Real(String),
    Integer(i64),
    String(String),
    Boolean(bool),
    Array(Array),
    Hash(Hash),
    Alias(usize),
    Null,
    BadValue,
}

An YAML node is store as this Yaml enumeration, it provides an easy way to access your YAML document.

Examples

use yaml_rust::Yaml;
let foo = Yaml::from_str("-123"); // convert the string to the appropriate YAML type
assert_eq!(foo.as_i64().unwrap(), -123);

// iterator over an Array
let vec = Yaml::Array(vec![Yaml::Integer(1), Yaml::Integer(2)]);
for v in vec.as_vec().unwrap() {
    assert!(v.as_i64().is_some());
}

Variants

Real(String)

float types are stored as String, and parsed on demand. Note that f64 does NOT implement Eq trait and can NOT be stored in BTreeMap

Integer(i64)

Yaml int is stored as i64.

String(String)

Yaml scalar.

Boolean(bool)

Yaml bool, e.g. true or false.

Array(Array)

Yaml array, can be access as a Vec.

Hash(Hash)

Yaml hash, can be access as a BTreeMap.

Alias(usize)

Alias, not fully supported yet.

Null

Yaml bool, e.g. null or ~.

BadValue

Access non-exist node by Index trait will return BadValue. This simplifies error handling of user. Invalid type conversion also return BadValue.

Methods

impl Yaml
[src]

fn as_bool(&self) -> Option<bool>

fn as_i64(&self) -> Option<i64>

fn as_str(&self) -> Option<&str>

fn as_hash(&self) -> Option<&Hash>

fn as_vec(&self) -> Option<&Array>

fn is_null(&self) -> bool

fn is_badvalue(&self) -> bool

fn as_f64(&self) -> Option<f64>

fn from_str(v: &str) -> Yaml

Trait Implementations

impl Ord for Yaml
[src]

fn cmp(&self, __arg_0: &Yaml) -> Ordering

This method returns an Ordering between self and other. Read more

impl Eq for Yaml
[src]

impl Debug for Yaml
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.

impl PartialOrd for Yaml
[src]

fn partial_cmp(&self, __arg_0: &Yaml) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

fn lt(&self, __arg_0: &Yaml) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more

fn le(&self, __arg_0: &Yaml) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

fn gt(&self, __arg_0: &Yaml) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more

fn ge(&self, __arg_0: &Yaml) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialEq for Yaml
[src]

fn eq(&self, __arg_0: &Yaml) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, __arg_0: &Yaml) -> bool

This method tests for !=.

impl Clone for Yaml
[src]

fn clone(&self) -> Yaml

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<'a> Index<&'a str> for Yaml
[src]

type Output = Yaml

The returned type after indexing

fn index(&self, idx: &'a str) -> &Yaml

The method for the indexing (Foo[Bar]) operation

impl Index<usize> for Yaml
[src]

type Output = Yaml

The returned type after indexing

fn index(&self, idx: usize) -> &Yaml

The method for the indexing (Foo[Bar]) operation