Struct DefinitionBuilder

Source
pub struct DefinitionBuilder<'def> {
    pub entries: Vec<Entry<'def>>,
}
Expand description

Builder for definition entries

Fields§

§entries: Vec<Entry<'def>>

Implementations§

Source§

impl<'def> DefinitionBuilder<'def>

Source

pub fn function<'lua, Params, Returns>( self, name: impl Into<Cow<'def, str>>, _: impl IntoTypedFunction<'lua, Params, Returns>, ) -> Self
where Params: TypedMultiValue, Returns: TypedMultiValue,

Register a definition entry that is a function type

Source

pub fn function_with<'lua, Params, Returns, F>( self, name: impl Into<Cow<'def, str>>, _: impl IntoTypedFunction<'lua, Params, Returns>, generator: F, ) -> Self
where Params: TypedMultiValue, Returns: TypedMultiValue, F: Fn(&mut FunctionBuilder<Params, Returns>),

Register a definition entry that is a function type

Also add additional documentation

Source

pub fn alias(self, name: impl Into<Cow<'static, str>>, ty: Type) -> Self

Register a definition entry that is an alias type

Source

pub fn alias_with<S: Into<Cow<'def, str>>>( self, name: impl Into<Cow<'def, str>>, ty: Type, doc: Option<S>, ) -> Self

Register a definition entry that is an alias type

Also add additional documentation

Source

pub fn register_class<T: TypedUserData>(self) -> Self

Register a definition entry that is a class type

The name of the class is the same as the name of the type passed

Source

pub fn register_class_with<T: TypedUserData, S: Into<Cow<'def, str>>>( self, doc: Option<S>, ) -> Self

Same as register_class but with additional docs

Source

pub fn register_module<T: TypedModule>( self, name: impl Into<Cow<'def, str>>, ) -> Self

Register a definition entry that is a class type

The name of the class is the same as the name of the type passed

Source

pub fn register_module_with<T: TypedModule, S: Into<Cow<'def, str>>>( self, name: impl Into<Cow<'def, str>>, doc: Option<S>, ) -> Self

Same as register_module but with additional docs

Source

pub fn register_enum<T: Typed>(self) -> Result<Self>

Register a definition entry that is a enum type

This is equal to an alias, but is usually derived from using the Typed derive macro on an enum object.

Returns an error response of Error::RuntimeError if the type extracted was not Type::Enum

§Example
use mlua_extras::{Typed, typed::Type};

#[derive(Typed)]
enum Color {
    Red,
    White,
    Green,
    Yellow,
    Cyan,
    Blue,
    Magenta,
    Black
}

assert!(matches!(Color::ty(), Type::Enum(_, _)))
Source

pub fn register_enum_with<T: Typed, S: Into<Cow<'def, str>>>( self, doc: Option<S>, ) -> Result<Self>

Same as register but with additional docs

Source

pub fn value<T: Typed>(self, name: impl Into<Cow<'def, str>>) -> Self

Register a value that is available

This can be a table, union/enum, literal, or any other value and it will be typed with the given type

§Example
user mlua_extras::{typed::{Definitions, TypedUserData}, Typed, UserData};

#[derive(UserData, Typed)]
struct Example {
    color: String
}
impl TypedUserData for Example {
    fn add_documentation<F: mlua_extras::typed::TypedDataDocumentation<Self>>(docs: &mut F) {
        docs.add("This is an example");
    }
     
    fn add_fields<'lua, F: TypedDataFields<'lua, Self>>(fields: &mut F) {
        fields
            .document("Example field")
            .add_field_method_get_set(
                "color",
                |_lua, this| Ok(this.color),
                |_lua, this, clr: String| {
                    this.color = clr;
                    Ok(())
                },
            );
    }
}

Definitions::generate("init")
    .register::<Example>("Example")
    .value::<Example>("example")
    .finish();
--- init.d.lua
--- @meta

--- This is an example
--- @class Example
--- Example field
--- @field color string

--- The example module
--- @type Example
example = nil
Source

pub fn value_with<T: Typed, S: Into<Cow<'def, str>>>( self, name: impl Into<Cow<'def, str>>, doc: Option<S>, ) -> Self

Same as value but with additional docs

Source

pub fn finish(self) -> Definition<'def>

Finish the definition

Trait Implementations§

Source§

impl<'def> Clone for DefinitionBuilder<'def>

Source§

fn clone(&self) -> DefinitionBuilder<'def>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'def> Debug for DefinitionBuilder<'def>

Source§

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

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

impl<'def> Default for DefinitionBuilder<'def>

Source§

fn default() -> DefinitionBuilder<'def>

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

impl<'def> From<DefinitionBuilder<'def>> for Definition<'def>

Source§

fn from(value: DefinitionBuilder<'def>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'def> Freeze for DefinitionBuilder<'def>

§

impl<'def> RefUnwindSafe for DefinitionBuilder<'def>

§

impl<'def> Send for DefinitionBuilder<'def>

§

impl<'def> Sync for DefinitionBuilder<'def>

§

impl<'def> Unpin for DefinitionBuilder<'def>

§

impl<'def> UnwindSafe for DefinitionBuilder<'def>

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.
Source§

impl<T> MaybeSend for T
where T: Send,