Struct lune_utils::TableBuilder

source ·
pub struct TableBuilder<'lua> { /* private fields */ }
Expand description

Utility struct for building Lua tables.

Implementations§

source§

impl<'lua> TableBuilder<'lua>

source

pub fn new(lua: &'lua Lua) -> LuaResult<Self>

Creates a new table builder.

source

pub fn with_value<K, V>(self, key: K, value: V) -> LuaResult<Self>
where K: IntoLua<'lua>, V: IntoLua<'lua>,

Adds a new key-value pair to the table.

This will overwrite any value that already exists.

source

pub fn with_values<K, V>(self, values: Vec<(K, V)>) -> LuaResult<Self>
where K: IntoLua<'lua>, V: IntoLua<'lua>,

Adds multiple key-value pairs to the table.

This will overwrite any values that already exist.

source

pub fn with_sequential_value<V>(self, value: V) -> LuaResult<Self>
where V: IntoLua<'lua>,

Adds a new key-value pair to the sequential (array) section of the table.

This will not overwrite any value that already exists, instead adding the value to the end of the array.

source

pub fn with_sequential_values<V>(self, values: Vec<V>) -> LuaResult<Self>
where V: IntoLua<'lua>,

Adds multiple values to the sequential (array) section of the table.

This will not overwrite any values that already exist, instead adding the values to the end of the array.

source

pub fn with_function<K, A, R, F>(self, key: K, func: F) -> LuaResult<Self>
where K: IntoLua<'lua>, A: FromLuaMulti<'lua>, R: IntoLuaMulti<'lua>, F: Fn(&'lua Lua, A) -> LuaResult<R> + 'static,

Adds a new key-value pair to the table, with a function value.

This will overwrite any value that already exists.

source

pub fn with_async_function<K, A, R, F, FR>( self, key: K, func: F ) -> LuaResult<Self>
where K: IntoLua<'lua>, A: FromLuaMulti<'lua>, R: IntoLuaMulti<'lua>, F: Fn(&'lua Lua, A) -> FR + 'static, FR: Future<Output = LuaResult<R>> + 'lua,

Adds a new key-value pair to the table, with an async function value.

This will overwrite any value that already exists.

source

pub fn with_metatable(self, table: LuaTable<'_>) -> LuaResult<Self>

Adds a metatable to the table.

This will overwrite any metatable that already exists.

source

pub fn build_readonly(self) -> LuaResult<LuaTable<'lua>>

Builds the table as a read-only table.

This will prevent any direct modifications to the table.

source

pub fn build(self) -> LuaResult<LuaTable<'lua>>

Builds the table.

Auto Trait Implementations§

§

impl<'lua> Freeze for TableBuilder<'lua>

§

impl<'lua> !RefUnwindSafe for TableBuilder<'lua>

§

impl<'lua> !Send for TableBuilder<'lua>

§

impl<'lua> !Sync for TableBuilder<'lua>

§

impl<'lua> Unpin for TableBuilder<'lua>

§

impl<'lua> !UnwindSafe for TableBuilder<'lua>

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

§

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

§

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.