pub struct Value<'de> {
pub span: Span,
/* private fields */
}
Expand description
A deserialized ValueInner
with accompanying Span
information for where
it was located in the toml document
Fields§
§span: Span
The location of the value in the toml document
Implementations§
source§impl<'de> Value<'de>
impl<'de> Value<'de>
sourcepub fn new(value: ValueInner<'de>) -> Self
pub fn new(value: ValueInner<'de>) -> Self
sourcepub fn with_span(value: ValueInner<'de>, span: Span) -> Self
pub fn with_span(value: ValueInner<'de>, span: Span) -> Self
sourcepub fn take(&mut self) -> ValueInner<'de>
pub fn take(&mut self) -> ValueInner<'de>
Takes the inner ValueInner
This panics if the inner value has already been taken.
Typically paired with Self::set
sourcepub fn set(&mut self, value: ValueInner<'de>)
pub fn set(&mut self, value: ValueInner<'de>)
Sets the inner ValueInner
This is typically done when the value is taken with Self::take
,
processed, and returned
sourcepub fn has_key(&self, key: &str) -> bool
pub fn has_key(&self, key: &str) -> bool
Returns true if the value is a table and has the specified key
sourcepub fn take_string(
&mut self,
msg: Option<&'static str>,
) -> Result<Cow<'de, str>, Error>
pub fn take_string( &mut self, msg: Option<&'static str>, ) -> Result<Cow<'de, str>, Error>
Takes the value as a string, returning an error with either a default or user supplied message
sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns a borrowed string if this is a ValueInner::String
sourcepub fn as_table(&self) -> Option<&Table<'de>>
pub fn as_table(&self) -> Option<&Table<'de>>
Returns a borrowed table if this is a ValueInner::Table
sourcepub fn as_array(&self) -> Option<&Array<'de>>
pub fn as_array(&self) -> Option<&Array<'de>>
Returns a borrowed array if this is a ValueInner::Array
sourcepub fn as_integer(&self) -> Option<i64>
pub fn as_integer(&self) -> Option<i64>
Returns an i64
if this is a ValueInner::Integer
sourcepub fn as_float(&self) -> Option<f64>
pub fn as_float(&self) -> Option<f64>
Returns an f64
if this is a ValueInner::Float
sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Returns a bool
if this is a ValueInner::Boolean
sourcepub fn pointer(&self, pointer: &'de str) -> Option<&Self>
pub fn pointer(&self, pointer: &'de str) -> Option<&Self>
Uses JSON pointer-like syntax to lookup a specific Value
The basic format is:
- The path starts with
/
- Each segment is separated by a
/
- Each segment is either a key name, or an integer array index
let data = "[x]\ny = ['z', 'zz']";
let value = toml_span::parse(data).unwrap();
assert_eq!(value.pointer("/x/y/1").unwrap().as_str().unwrap(), "zz");
assert!(value.pointer("/a/b/c").is_none());
Note that this is JSON pointer**-like** because /
is not supported in
key names because I don’t see the point. If you want this it is easy to
implement.
sourcepub fn pointer_mut(&mut self, pointer: &'de str) -> Option<&mut Self>
pub fn pointer_mut(&mut self, pointer: &'de str) -> Option<&mut Self>
The mut
version of Self::pointer