Skip to main content

Table

Struct Table 

Source
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

Source

pub fn new() -> Self

Create an empty table.

Source

pub fn push(&self, v: Value)

Append a value to the array part at the next integer index.

Source

pub fn set(&self, key: Key, value: Value)

Set key to value. Replaces an existing entry with an equal key.

Source

pub fn border(&self) -> usize

The Lua # length: a border of the array part. This model uses the contiguous integer prefix from 1.

Source

pub fn is_empty(&self) -> bool

True when the table has no entries.

Source

pub fn id(&self) -> usize

Raw pointer used for identity comparison and hashing.

Source

pub fn set_serialize_meta(&self, f: MetaFn)

Set the __serialize metamethod.

Source

pub fn set_tostring_meta(&self, f: MetaFn)

Set the __tostring metamethod.

Source

pub fn serialize_meta(&self) -> Option<MetaFn>

The __serialize metamethod, if set.

Source

pub fn tostring_meta(&self) -> Option<MetaFn>

The __tostring metamethod, if set.

Source

pub fn get(&self, key: &Key) -> Option<Value>

The value for key, if present. Compares keys with Key::same.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Table

Source§

fn clone(&self) -> Table

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Table

Source§

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

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

impl Default for Table

Source§

fn default() -> Self

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

impl PartialEq for Table

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Table

§

impl !Send for Table

§

impl !Sync for Table

§

impl !UnwindSafe for Table

§

impl Freeze for Table

§

impl Unpin for Table

§

impl UnsafeUnpin for Table

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.