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 | |
Integer | |
Float | |
Boolean | |
Datetime | |
Array | |
Table |
Methods
impl Value
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);