pub enum Value {
String(String),
Integer(i64),
Float(f64),
Boolean(bool),
Datetime(String),
Array(Array),
Table(Table),
}Expand description
Representation of a TOML value.
Variants§
Implementations§
source§impl Value
impl Value
sourcepub fn same_type(&self, other: &Value) -> bool
pub fn same_type(&self, other: &Value) -> bool
Tests whether this and another value have the same type.
sourcepub fn type_str(&self) -> &'static str
pub fn type_str(&self) -> &'static str
Returns a human-readable representation of the type of this value.
sourcepub fn as_integer(&self) -> Option<i64>
pub fn as_integer(&self) -> Option<i64>
Extracts the integer value if it is an integer.
sourcepub fn as_datetime(&self) -> Option<&str>
pub 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
sourcepub fn lookup<'a>(&'a self, path: &'a str) -> Option<&'a Value>
pub 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);Trait Implementations§
source§impl PartialEq for Value
impl PartialEq for Value
impl StructuralPartialEq for Value
Auto Trait Implementations§
impl Freeze for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)