pub struct OwnedItem { /* private fields */ }Expand description
A self-contained TOML value that owns its backing storage.
An Item normally borrows from an Arena.
OwnedItem bundles the value with its own allocation so it can
be stored, returned, or moved independently of any parse context.
Create one by converting from an Item reference or value, or
deserialize directly via FromToml. Access
the underlying Item through item().
FromFlattened is not provided because
flatten_any is more performant
than direct implementation could be. See OwnedTable for an example.
§Examples
use toml_spanner::{Arena, OwnedItem, parse};
let arena = Arena::new();
let doc = parse("greeting = 'hello'", &arena).unwrap();
let owned = OwnedItem::from(doc.table()["greeting"].item().unwrap());
drop(arena);
assert_eq!(owned.as_str(), Some("hello"));Implementations§
Source§impl OwnedItem
impl OwnedItem
Sourcepub fn span(&self) -> Span
pub fn span(&self) -> Span
Returns the source span, or 0..0 if this item was constructed
programmatically (format-hints mode).
Sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
Returns an i64 if this is an integer value that fits in the i64 range.
Sourcepub fn as_u64(&self) -> Option<u64>
pub fn as_u64(&self) -> Option<u64>
Returns a u64 if this is an integer value that fits in the u64 range.
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<'a>(&'a self) -> Option<&'a Array<'a>>
pub fn as_array<'a>(&'a self) -> Option<&'a Array<'a>>
Returns a borrowed array if this is an array value.
Sourcepub fn as_table<'a>(&'a self) -> Option<&'a Table<'a>>
pub fn as_table<'a>(&'a self) -> Option<&'a Table<'a>>
Returns a borrowed table if this is a table value.
Sourcepub fn as_datetime(&self) -> Option<&DateTime>
pub fn as_datetime(&self) -> Option<&DateTime>
Returns a borrowed DateTime if this is a datetime value.
Trait Implementations§
Source§impl ToFlattened for OwnedItem
Available on crate feature to-toml only.
impl ToFlattened for OwnedItem
to-toml only.Source§fn to_flattened<'a>(
&'a self,
arena: &'a Arena,
table: &mut Table<'a>,
) -> Result<(), ToTomlError>
fn to_flattened<'a>( &'a self, arena: &'a Arena, table: &mut Table<'a>, ) -> Result<(), ToTomlError>
Source§impl ToToml for OwnedItem
Available on crate feature to-toml only.
impl ToToml for OwnedItem
to-toml only.