Skip to main content

OwnedTable

Struct OwnedTable 

Source
pub struct OwnedTable { /* private fields */ }
Expand description

A self-contained TOML table that owns its backing storage.

The table-specific counterpart of OwnedItem. The inner value is always a table, so table() is infallible.

§Flattening

FromFlattened is not provided because flatten_any is more performant than direct implementation could be, due to current trait definition.

use toml_spanner::Toml;
use toml_spanner::helper::flatten_any;

#[derive(Toml)]
#[toml(Toml)]
struct Config {
    name: String,
    #[toml(flatten, with = flatten_any)]
    extra: OwnedTable,
}

§Examples

use toml_spanner::OwnedTable;

let owned: OwnedTable = toml_spanner::from_str("
host = 'localhost'
port = 8080
").unwrap();

assert_eq!(owned.get("host").unwrap().as_str(), Some("localhost"));
assert_eq!(owned.len(), 2);

Implementations§

Source§

impl OwnedTable

Source

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

Returns a reference to the contained Table.

Source

pub fn span(&self) -> Span

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

Source

pub fn len(&self) -> usize

Returns the number of entries.

Source

pub fn is_empty(&self) -> bool

Returns true if the table has no entries.

Source

pub fn get_key_value<'a>( &'a self, name: &str, ) -> Option<(&'a Key<'a>, &'a Item<'a>)>

Returns references to both key and value for name.

Source

pub fn get<'a>(&'a self, name: &str) -> Option<&'a Item<'a>>

Returns a reference to the value for name.

Source

pub fn contains_key(&self, name: &str) -> bool

Returns true if the table contains the key.

Source

pub fn entries<'a>(&'a self) -> &'a [(Key<'a>, Item<'a>)]

Returns a slice of all entries.

Source

pub fn iter<'a>(&'a self) -> Iter<'a, (Key<'a>, Item<'a>)>

Returns an iterator over all entries (key-value pairs).

Source

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

Returns the contained table as an Item reference.

Source

pub fn style(&self) -> TableStyle

Returns the kind of this table (implicit, dotted, header, or inline).

Trait Implementations§

Source§

impl Clone for OwnedTable

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 OwnedTable

Source§

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

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

impl From<&Table<'_>> for OwnedTable

Source§

fn from(value: &Table<'_>) -> Self

Converts to this type from the input type.
Source§

impl<'a> FromToml<'a> for OwnedTable

Available on crate feature from-toml only.
Source§

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

Attempts to construct Self from a TOML Item.
Source§

impl<'a> IntoIterator for &'a OwnedTable

Source§

type Item = &'a (Key<'a>, Item<'a>)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, (Key<'a>, Item<'a>)>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for OwnedTable

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 OwnedTable

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 OwnedTable

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 OwnedTable

Source§

impl Sync for OwnedTable

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.