Skip to main content

Table

Struct Table 

Source
pub struct Table<'de> { /* private fields */ }
Expand description

A TOML table with span information.

A Table is the top-level value returned by parse and is also the value inside any [section] or inline { ... } table in TOML. It stores (Key, Item) pairs in insertion order.

§Accessing values

  • Index operatorstable["key"] returns a MaybeItem that never panics on missing keys, and supports chained indexing.
  • get / get_mut — return Option<&Item> / Option<&mut Item>.

For type-safe deserialization, use Item::table_helper to create a TableHelper.

§Lookup performance

Direct lookups (get, table["key"]) perform a linear scan over entries — O(n) in the number of keys. For small tables or a handful of lookups, as is typical in TOML, this is well fast enough.

For structured deserialization of larger tables, use TableHelper via Root::helper or Item::table_helper. The Context returned by parse carries the parser’s hash index.

§Constructing tables

Tables are normally obtained from parse. To build one programmatically, create a table with Table::new and insert entries with Table::insert. An Arena is required for insertion because entries are arena-allocated.

§Iteration

Table implements IntoIterator (both by reference and by value), yielding (Key, Item) pairs.

Removal via remove_entry uses swap-remove and may reorder remaining entries.

Implementations§

Source§

impl<'de> Table<'de>

Source

pub fn new(span: Span) -> Table<'de>

Creates an empty table with the given span.

Source

pub fn span(&self) -> Span

Returns the byte-offset span of this table in the source document.

Source§

impl<'de> Table<'de>

Source

pub fn insert(&mut self, key: Key<'de>, value: Item<'de>, arena: &'de Arena)

Inserts a key-value pair. Does not check for duplicates.

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(&self, name: &str) -> Option<(&Key<'de>, &Item<'de>)>

Linear scan for a key, returning both key and value references.

Source

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

Returns a reference to the value for name.

Source

pub fn get_mut(&mut self, name: &str) -> Option<&mut Item<'de>>

Returns a mutable 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 remove_entry(&mut self, name: &str) -> Option<(Key<'de>, Item<'de>)>

Removes the first entry matching name, returning the key-value pair. Uses swap-remove, so the ordering of remaining entries may change.

Source

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

Returns a slice of all entries.

Source

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

Converts this Table into an Item with the same span and payload.

Source

pub fn into_item(self) -> Item<'de>

Converts this Table into an Item with the same span and payload.

Trait Implementations§

Source§

impl Debug for Table<'_>

Source§

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

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

impl<'de> Default for Table<'de>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Index<&str> for Table<'de>

Source§

type Output = MaybeItem<'de>

The returned type after indexing.
Source§

fn index(&self, index: &str) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, 'de> IntoIterator for &'a Table<'de>

Source§

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

The type of the elements being iterated over.
Source§

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

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<'a, 'de> IntoIterator for &'a mut Table<'de>

Source§

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

The type of the elements being iterated over.
Source§

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

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<'de> IntoIterator for Table<'de>

Source§

type Item = (Key<'de>, Item<'de>)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<'de>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'de> Freeze for Table<'de>

§

impl<'de> RefUnwindSafe for Table<'de>

§

impl<'de> !Send for Table<'de>

§

impl<'de> !Sync for Table<'de>

§

impl<'de> Unpin for Table<'de>

§

impl<'de> UnsafeUnpin for Table<'de>

§

impl<'de> UnwindSafe for Table<'de>

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