Enum toml::Value [] [src]

pub enum Value {
    String(String),
    Integer(i64),
    Float(f64),
    Boolean(bool),
    Datetime(String),
    Array(Array),
    Table(Table),
}

Representation of a TOML value.

Variants

Methods

impl Value
[src]

Tests whether this and another value have the same type.

Returns a human-readable representation of the type of this value.

Extracts the string of this value if it is a string.

Extracts the integer value if it is an integer.

Extracts the float value if it is a float.

Extracts the boolean value if it is a boolean.

Extracts the datetime value if it is a datetime.

Note that a parsed TOML value will only contain ISO 8601 dates. An example date is:

1979-05-27T07:32:00Z

Extracts the array value if it is an array.

Extracts the table value if it is a table.

Lookups for value at specified path.

Uses '.' as a path separator.

Note: arrays have zero-based indexes.

Note: empty path returns self.

let toml = r#"
     [test]
     foo = "bar"

     [[values]]
     foo = "baz"

     [[values]]
     foo = "qux"
"#;
let value: toml::Value = toml.parse().unwrap();

let foo = value.lookup("test.foo").unwrap();
assert_eq!(foo.as_str().unwrap(), "bar");

let foo = value.lookup("values.1.foo").unwrap();
assert_eq!(foo.as_str().unwrap(), "qux");

let no_bar = value.lookup("test.bar");
assert_eq!(no_bar.is_none(), true);

Lookups for mutable value at specified path.

Uses '.' as a path separator.

Note: arrays have zero-based indexes.

Note: empty path returns self.

let toml = r#"
     [test]
     foo = "bar"

     [[values]]
     foo = "baz"

     [[values]]
     foo = "qux"
"#;
let mut value: toml::Value = toml.parse().unwrap();
{
   let string = value.lookup_mut("test.foo").unwrap();
   assert_eq!(string, &mut toml::Value::String(String::from("bar")));
   *string = toml::Value::String(String::from("foo"));
}
let result = value.lookup_mut("test.foo").unwrap();
assert_eq!(result.as_str().unwrap(), "foo");

Trait Implementations

impl Display for Value
[src]

Formats the value using the given formatter.

impl Encodable for Value
[src]

impl PartialEq for Value
[src]

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

This method tests for !=.

impl Clone for Value
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Value
[src]

Formats the value using the given formatter.

impl FromStr for Value
[src]

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more