pub enum Value {
Integer(i64),
Float(f64),
Boolean(bool),
Datetime(Datetime),
String(String),
Array(Array),
Table(Table),
}
Expand description
Representation of a TOML value.
Variants
Integer(i64)
Represents a TOML integer
Float(f64)
Represents a TOML float
Boolean(bool)
Represents a TOML boolean
Datetime(Datetime)
Represents a TOML datetime
String(String)
Represents a TOML string
Array(Array)
Represents a TOML array
Table(Table)
Represents a TOML table
Implementations
sourceimpl Value
impl Value
sourcepub fn try_from<T>(value: T) -> Result<Value, TomlError> where
T: Serialize,
pub fn try_from<T>(value: T) -> Result<Value, TomlError> where
T: Serialize,
Convert a T
into toml::Value
which is an enum that can represent
any valid TOML data.
This conversion can fail if T
’s implementation of Serialize
decides to
fail, or if T
contains a map with non-string keys.
sourcepub fn try_into<T>(self) -> Result<T, TomlError> where
T: DeserializeOwned,
pub fn try_into<T>(self) -> Result<T, TomlError> where
T: DeserializeOwned,
Interpret a toml::Value
as an instance of type T
.
This conversion can fail if the structure of the Value
does not match the
structure expected by T
, for example if T
is a struct type but the
Value
contains something other than a TOML table. It can also fail if the
structure is correct but T
’s implementation of Deserialize
decides that
something is wrong with the data, for example required struct fields are
missing from the TOML map or some number is too big to fit in the expected
primitive type.
sourcepub fn get<I: Index>(&self, index: I) -> Option<&Value>
pub fn get<I: Index>(&self, index: I) -> Option<&Value>
Index into a TOML array or map. A string index can be used to access a value in a map, and a usize index can be used to access an element of an array.
Returns None
if the type of self
does not match the type of the
index, for example if the index is a string and self
is an array or a
number. Also returns None
if the given key does not exist in the map
or the given index is not within the bounds of the array.
sourcepub fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut Value>
pub fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut Value>
Mutably index into a TOML array or map. A string index can be used to access a value in a map, and a usize index can be used to access an element of an array.
Returns None
if the type of self
does not match the type of the
index, for example if the index is a string and self
is an array or a
number. Also returns None
if the given key does not exist in the map
or the given index is not within the bounds of the array.
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 is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Tests whether this value is an integer.
sourcepub fn as_datetime(&self) -> Option<&Datetime>
pub fn as_datetime(&self) -> Option<&Datetime>
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 is_datetime(&self) -> bool
pub fn is_datetime(&self) -> bool
Tests whether this value is a datetime.
sourcepub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>
pub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>
Extracts the array value if it is an array.
sourcepub fn as_table_mut(&mut self) -> Option<&mut Table>
pub fn as_table_mut(&mut self) -> Option<&mut Table>
Extracts the table value if it is a table.
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
sourcefn deserialize<D>(deserializer: D) -> Result<Value, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Value, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Value
Auto Trait Implementations
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more