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 operators —
table["key"]returns aMaybeItemthat never panics on missing keys, and supports chained indexing. get/get_mut— returnOption<&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>
impl<'de> Table<'de>
Sourcepub fn insert(&mut self, key: Key<'de>, value: Item<'de>, arena: &'de Arena)
pub fn insert(&mut self, key: Key<'de>, value: Item<'de>, arena: &'de Arena)
Inserts a key-value pair. Does not check for duplicates.
Sourcepub fn get_key_value(&self, name: &str) -> Option<(&Key<'de>, &Item<'de>)>
pub fn get_key_value(&self, name: &str) -> Option<(&Key<'de>, &Item<'de>)>
Linear scan for a key, returning both key and value references.
Sourcepub fn get_mut(&mut self, name: &str) -> Option<&mut Item<'de>>
pub fn get_mut(&mut self, name: &str) -> Option<&mut Item<'de>>
Returns a mutable reference to the value for name.
Sourcepub fn contains_key(&self, name: &str) -> bool
pub fn contains_key(&self, name: &str) -> bool
Returns true if the table contains the key.
Sourcepub fn remove_entry(&mut self, name: &str) -> Option<(Key<'de>, Item<'de>)>
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.