pub struct Table(/* private fields */);Expand description
A shared table handle.
Cloning a Table shares the same underlying storage, so identity is
preserved. Use Table::new to build one and the insertion helpers to fill
it.
Equality is by identity. Two Table handles are equal when they point at the
same storage, matching Lua reference semantics. Contents are not compared.
The storage is private. Read contents through Table::get,
Table::entries, or Table::with_entries, and write through push,
set, and the meta setters.
Implementations§
Source§impl Table
impl Table
Sourcepub fn set(&self, key: Key, value: Value)
pub fn set(&self, key: Key, value: Value)
Set key to value. Replaces an existing entry with an equal key.
Sourcepub fn border(&self) -> usize
pub fn border(&self) -> usize
The Lua # length: a border of the array part. This model uses the
contiguous integer prefix from 1.
Sourcepub fn set_serialize_meta(&self, f: MetaFn)
pub fn set_serialize_meta(&self, f: MetaFn)
Set the __serialize metamethod.
Sourcepub fn set_tostring_meta(&self, f: MetaFn)
pub fn set_tostring_meta(&self, f: MetaFn)
Set the __tostring metamethod.
Sourcepub fn serialize_meta(&self) -> Option<MetaFn>
pub fn serialize_meta(&self) -> Option<MetaFn>
The __serialize metamethod, if set.
Sourcepub fn tostring_meta(&self) -> Option<MetaFn>
pub fn tostring_meta(&self) -> Option<MetaFn>
The __tostring metamethod, if set.
Sourcepub fn get(&self, key: &Key) -> Option<Value>
pub fn get(&self, key: &Key) -> Option<Value>
The value for key, if present. Compares keys with Key::same.
Sourcepub fn entries(&self) -> Vec<(Key, Value)>
pub fn entries(&self) -> Vec<(Key, Value)>
A snapshot of the key/value pairs in insertion order.
This clones the entries. For a read-only pass without a clone, use
Table::with_entries.
Sourcepub fn with_entries<R>(&self, f: impl FnOnce(&[(Key, Value)]) -> R) -> R
pub fn with_entries<R>(&self, f: impl FnOnce(&[(Key, Value)]) -> R) -> R
Run f over a borrow of the key/value pairs and return its result.
This avoids cloning the entries when a read pass is enough. The borrow is
held for the duration of f, so f must not call back into methods that
borrow the same table mutably.