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

String(String)Integer(i64)Float(f64)Boolean(bool)Datetime(String)Array(Array)Table(Table)

Methods

impl Value
[src]

fn same_type(&self, other: &Value) -> bool

Tests whether this and another value have the same type.

fn type_str(&self) -> &'static str

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

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

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

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

Extracts the integer value if it is an integer.

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

Extracts the float value if it is a float.

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

Extracts the boolean value if it is a boolean.

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

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

fn as_slice(&self) -> Option<&[Value]>

Extracts the array value if it is an array.

fn as_table(&self) -> Option<&Table>

Extracts the table value if it is a table.

fn lookup<'a>(&'a self, path: &'a str) -> Option<&'a Value>

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);

fn lookup_mut(&mut self, path: &str) -> Option<&mut Value>

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]

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

Formats the value using the given formatter.

impl Encodable for Value
[src]

fn encode<E>(&self, e: &mut E) -> Result<(), E::Error> where E: Encoder

impl Debug for Value
[src]

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

Formats the value using the given formatter.

impl Clone for Value
[src]

fn clone(&self) -> Value

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 Value
[src]

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

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

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

This method tests for !=.

impl FromStr for Value
[src]

type Err = Vec<ParserError>

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<ValueVec<ParserError>>

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