pub struct Item<'de> { /* private fields */ }Expand description
A parsed TOML value with span information.
Use the as_* methods (as_str,
as_i64, as_table, etc.) to
extract the value, or call value /
value_mut to pattern match via the Value /
ValueMut enums.
Items support indexing with &str (table lookup) and usize (array
access). These operators return MaybeItem and never panic — missing
keys or out-of-bounds indices produce a None variant instead.
§Examples
let arena = toml_spanner::Arena::new();
let table = toml_spanner::parse("x = 42", &arena)?;
assert_eq!(table["x"].as_i64(), Some(42));
assert_eq!(table["missing"].as_i64(), None);Implementations§
Source§impl<'de> Item<'de>
impl<'de> Item<'de>
Sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Returns an f64 if this is a float or integer value.
Integer values are converted to f64 via as cast (lossy for large
values outside the 2^53 exact-integer range).
Sourcepub fn as_array(&self) -> Option<&Array<'de>>
pub fn as_array(&self) -> Option<&Array<'de>>
Returns a borrowed array if this is an array value.
Sourcepub fn as_table(&self) -> Option<&Table<'de>>
pub fn as_table(&self) -> Option<&Table<'de>>
Returns a borrowed table if this is a table value.
Sourcepub fn expect_array(&mut self) -> Result<&mut Array<'de>, Error>
pub fn expect_array(&mut self) -> Result<&mut Array<'de>, Error>
Returns a mutable array reference, or an error if this is not an array.
Sourcepub fn expect_table(&mut self) -> Result<&mut Table<'de>, Error>
pub fn expect_table(&mut self) -> Result<&mut Table<'de>, Error>
Returns a mutable table reference, or an error if this is not a table.
This is the typical entry point for implementing Deserialize.
Sourcepub fn as_array_mut(&mut self) -> Option<&mut Array<'de>>
pub fn as_array_mut(&mut self) -> Option<&mut Array<'de>>
Returns a mutable array reference.
Sourcepub fn as_table_mut(&mut self) -> Option<&mut Table<'de>>
pub fn as_table_mut(&mut self) -> Option<&mut Table<'de>>
Returns a mutable table reference.
Source§impl<'de> Item<'de>
impl<'de> Item<'de>
Sourcepub fn expected(&self, expected: &'static str) -> Error
pub fn expected(&self, expected: &'static str) -> Error
Creates an “expected X, found Y” error using this value’s type and span.
Sourcepub fn parse<T, E>(&mut self) -> Result<T, Error>
pub fn parse<T, E>(&mut self) -> Result<T, Error>
Takes a string value and parses it via std::str::FromStr.
Returns an error if the value is not a string or parsing fails.