Skip to main content

OwnedItem

Struct OwnedItem 

Source
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

Source

pub fn item<'a>(&'a self) -> &'a Item<'a>

Returns a reference to the contained Item.

The returned item borrows from self and provides the same accessor methods as any other Item (as_str(), as_table(), value(), etc.).

Source

pub fn kind(&self) -> Kind

Returns the type discriminant of this value.

Source

pub fn span(&self) -> Span

Returns the source span, or 0..0 if this item was constructed programmatically (format-hints mode).

Source

pub fn as_str(&self) -> Option<&str>

Returns a borrowed string if this is a string value.

Source

pub fn as_i128(&self) -> Option<i128>

Returns an i128 if this is an integer value.

Source

pub fn as_i64(&self) -> Option<i64>

Returns an i64 if this is an integer value that fits in the i64 range.

Source

pub fn as_u64(&self) -> Option<u64>

Returns a u64 if this is an integer value that fits in the u64 range.

Source

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).

Source

pub fn as_bool(&self) -> Option<bool>

Returns a bool if this is a boolean value.

Source

pub fn as_array<'a>(&'a self) -> Option<&'a Array<'a>>

Returns a borrowed array if this is an array value.

Source

pub fn as_table<'a>(&'a self) -> Option<&'a Table<'a>>

Returns a borrowed table if this is a table value.

Source

pub fn as_datetime(&self) -> Option<&DateTime>

Returns a borrowed DateTime if this is a datetime value.

Source

pub fn value<'a>(&'a self) -> Value<'a, 'a>

Returns a borrowed view for pattern matching.

Source

pub fn has_keys(&self) -> bool

Returns true if the value is a non-empty table.

Source

pub fn has_key(&self, key: &str) -> bool

Returns true if the value is a table containing key.

Trait Implementations§

Source§

impl Clone for OwnedItem

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OwnedItem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for OwnedItem

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a> From<&Item<'a>> for OwnedItem

Source§

fn from(item: &Item<'a>) -> Self

Creates an OwnedItem by copying item into a single managed allocation.

All strings (keys and values) are copied, and all table/array backing storage is laid out in one contiguous buffer. The result is fully independent of the source arena.

Source§

impl<'a> From<Item<'a>> for OwnedItem

Source§

fn from(item: Item<'a>) -> Self

Creates an OwnedItem by copying item into a single managed allocation.

This is a convenience wrapper that delegates to From<&Item>.

Source§

impl<'a> FromToml<'a> for OwnedItem

Available on crate feature from-toml only.
Source§

fn from_toml(_: &mut Context<'a>, item: &Item<'a>) -> Result<Self, Failed>

Attempts to construct Self from a TOML Item.
Source§

impl PartialEq for OwnedItem

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ToFlattened for OwnedItem

Available on crate feature to-toml only.
Source§

fn to_flattened<'a>( &'a self, arena: &'a Arena, table: &mut Table<'a>, ) -> Result<(), ToTomlError>

Inserts this value’s entries directly into an existing table. Read more
Source§

impl ToToml for OwnedItem

Available on crate feature to-toml only.
Source§

fn to_toml<'a>(&'a self, arena: &'a Arena) -> Result<Item<'a>, ToTomlError>

Produces a TOML Item representing this value. Read more
Source§

fn to_optional_toml<'a>( &'a self, arena: &'a Arena, ) -> Result<Option<Item<'a>>, ToTomlError>

Produces an optional TOML Item representing this value. Read more
Source§

impl Send for OwnedItem

Source§

impl Sync for OwnedItem

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.