TypedModuleBuilder

Struct TypedModuleBuilder 

Source
pub struct TypedModuleBuilder {
    pub doc: Option<Cow<'static, str>>,
    pub nested_modules: BTreeMap<Index, TypedModuleBuilder>,
    pub fields: BTreeMap<Index, Field>,
    pub meta_fields: BTreeMap<Index, Field>,
    pub functions: BTreeMap<Index, Func>,
    pub methods: BTreeMap<Index, Func>,
    pub meta_functions: BTreeMap<Index, Func>,
    pub meta_methods: BTreeMap<Index, Func>,
    /* private fields */
}
Expand description

Builder that constructs type and documentation information for a module using the TypedModule trait

Fields§

§doc: Option<Cow<'static, str>>§nested_modules: BTreeMap<Index, TypedModuleBuilder>§fields: BTreeMap<Index, Field>§meta_fields: BTreeMap<Index, Field>§functions: BTreeMap<Index, Func>§methods: BTreeMap<Index, Func>§meta_functions: BTreeMap<Index, Func>§meta_methods: BTreeMap<Index, Func>

Implementations§

Source§

impl TypedModuleBuilder

Source

pub fn new<M: TypedModule>() -> Result<Self>

Source

pub fn is_empty(&self) -> bool

Source

pub fn is_meta_empty(&self) -> bool

Source

pub fn field<S: AsRef<str>>( self, name: impl AsRef<str>, ty: Type, doc: impl IntoDocComment, ) -> Self

Creates a new typed field and adds it to the class’s type information

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

static NAME: &str = "mlua_extras";

TypedModuleBuilder::default()
    .field("data1", Type::string() | Type::nil(), "doc comment goes last")
    .field("data2", Type::array(Type::string()), ()) // Can also use `None` instead of `()`
    .field("message", Type::string(), foramt!("A message for {NAME}"))
Source

pub fn function<Params, Returns>( self, name: impl AsRef<str>, doc: impl IntoDocComment, ) -> Self
where Params: TypedMultiValue, Returns: TypedMultiValue,

Creates a new typed function and adds it to the class’s type information

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

TypedModuleBuilder::default()
    .function::<String, ()>("greet", "Greet the given name")
    // Can use `None` instead of `()` for specifying the doc comment
    .function::<String, ()>("hello", ())
Source

pub fn function_with<Params, Returns, F, R>( self, name: impl AsRef<str>, doc: impl IntoDocComment, generator: F, ) -> Self
where Params: TypedMultiValue, Returns: TypedMultiValue, F: Fn(&mut FunctionBuilder<Params, Returns>) -> R, R: Any,

Same as function but with an extra generator function parameter.

This extra parameter allows for customization of parameter names, types, and doc comments along with return types and doc comments.

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

TypedModuleBuilder::default()
    // Can use `None` instead of `()` for specifying the doc comment
    .function_with::<String, String>("getMessage", (), |func| {
        func.param(0, |param| param.name("name").doc("Name to use when constructing the message"));
        func.ret(0, |ret| ret.doc("Message constructed using the provided name"))
    })
Source

pub fn method<Params, Returns>( self, name: impl AsRef<str>, doc: impl IntoDocComment, ) -> Self
where Params: TypedMultiValue, Returns: TypedMultiValue,

Creates a new typed method and adds it to the class’s type information.

As with methods in lua, the self parameter is implicit and has the same type as the parent class.

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

TypedModuleBuilder::default()
    .method::<String, ()>("greet", "Greet the given name")
    // Can use `None` instead of `()` for specifying the doc comment
    .method::<String, ()>("hello", ())
Source

pub fn method_with<Params, Returns, F, R>( self, name: impl AsRef<str>, doc: impl IntoDocComment, generator: F, ) -> Self
where Params: TypedMultiValue, Returns: TypedMultiValue, F: Fn(&mut FunctionBuilder<Params, Returns>) -> R, R: Any,

Same as method but with an extra generator function parameter.

This extra parameter allows for customization of parameter names, types, and doc comments along with return types and doc comments.

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

TypedModuleBuilder::default()
    // Can use `None` instead of `()` for specifying the doc comment
    .method_with::<String, String>("getMessage", (), |func| {
        func.param(0, |param| param.name("name").doc("Name to use when constructing the message"));
        func.ret(0, |ret| ret.doc("Message constructed using the provided name"))
    })
Source

pub fn meta_field<S: AsRef<str>>( self, name: impl AsRef<str>, ty: Type, doc: impl IntoDocComment, ) -> Self

Creates a new typed field and adds it to the class’s meta type information

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

static NAME: &str = "mlua_extras";

TypedModuleBuilder::default()
    .meta_field("data1", Type::string() | Type::nil(), "doc comment goes last")
    .meta_field("data2", Type::array(Type::string()), ()) // Can also use `None` instead of `()`
    .meta_field("message", Type::string(), foramt!("A message for {NAME}"))
Source

pub fn meta_function<Params, Returns>( self, name: impl AsRef<str>, doc: impl IntoDocComment, ) -> Self
where Params: TypedMultiValue, Returns: TypedMultiValue,

Creates a new typed function and adds it to the class’s meta type information

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

TypedModuleBuilder::default()
    .meta_function::<String, ()>("greet", "Greet the given name")
    // Can use `None` instead of `()` for specifying the doc comment
    .meta_function::<String, ()>("hello", ())
Source

pub fn meta_function_with<Params, Returns, F, R>( self, name: impl AsRef<str>, doc: impl IntoDocComment, generator: F, ) -> Self
where F: Fn(&mut FunctionBuilder<Params, Returns>) -> R, R: Any, Params: TypedMultiValue, Returns: TypedMultiValue,

Same as meta_function but with an extra generator function parameter.

This extra parameter allows for customization of parameter names, types, and doc comments along with return types and doc comments.

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

TypedModuleBuilder::default()
    // Can use `None` instead of `()` for specifying the doc comment
    .meta_function_with::<String, String>("getMessage", (), |func| {
        func.param(0, |param| param.name("name").doc("Name to use when constructing the message"));
        func.ret(0, |ret| ret.doc("Message constructed using the provided name"))
    })
Source

pub fn meta_method<Params, Returns>( self, name: impl AsRef<str>, doc: impl IntoDocComment, ) -> Self
where Params: TypedMultiValue, Returns: TypedMultiValue,

Creates a new typed method and adds it to the class’s type information.

As with methods in lua, the self parameter is implicit and has the same type as the parent class.

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

static NAME: &str = "mlua_extras";

TypedModuleBuilder::default()
    .method::<String, ()>("greet", "Greet the given name")
    // Can use `None` instead of `()` for specifying the doc comment
    .method::<String, ()>("hello", ())
Source

pub fn meta_method_with<Params, Returns, F, R>( self, name: impl AsRef<str>, doc: impl IntoDocComment, generator: F, ) -> Self
where F: Fn(&mut FunctionBuilder<Params, Returns>) -> R, R: Any, Params: TypedMultiValue, Returns: TypedMultiValue,

Same as meta_method but with an extra generator function parameter.

This extra parameter allows for customization of parameter names, types, and doc comments along with return types and doc comments.

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

TypedModuleBuilder::default()
    // Can use `None` instead of `()` for specifying the doc comment
    .meta_method_with::<String, String>("getMessage", (), |func| {
        func.param(0, |param| param.name("name").doc("Name to use when constructing the message"));
        func.ret(0, |ret| ret.doc("Message constructed using the provided name"))
    })

Trait Implementations§

Source§

impl Clone for TypedModuleBuilder

Source§

fn clone(&self) -> TypedModuleBuilder

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 Debug for TypedModuleBuilder

Source§

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

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

impl Default for TypedModuleBuilder

Source§

fn default() -> TypedModuleBuilder

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

impl From<TypedModuleBuilder> for Type

Source§

fn from(value: TypedModuleBuilder) -> Self

Converts to this type from the input type.
Source§

impl Hash for TypedModuleBuilder

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for TypedModuleBuilder

Source§

fn cmp(&self, other: &TypedModuleBuilder) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for TypedModuleBuilder

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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.
Source§

impl PartialOrd for TypedModuleBuilder

Source§

fn partial_cmp(&self, other: &TypedModuleBuilder) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'lua> TypedModuleFields<'lua> for TypedModuleBuilder

Source§

fn document<V: AsRef<str>>(&mut self, doc: V) -> &mut Self

Queue a doc comment to be used with the nest add call
Source§

fn add_module<V>(&mut self, name: impl Into<Index>) -> Result<()>
where V: TypedModule,

Typed variant of add_module only collecting the type information
Source§

fn add_field<K, V>(&mut self, name: K, _value: V) -> Result<()>
where K: Into<Index>, V: IntoLua<'lua> + Typed,

Typed variant of add_field only collecting the type information
Source§

fn add_meta_field<K, V>(&mut self, name: K, _value: V) -> Result<()>
where K: Into<Index>, V: IntoLua<'lua> + Typed,

Typed variant of add_meta_field only collecting the type information
Source§

impl<'lua> TypedModuleMethods<'lua> for TypedModuleBuilder

Source§

fn document<V: AsRef<str>>(&mut self, doc: V) -> &mut Self

Queue a doc comment to be used with the nest add call
Source§

fn add_function<K, F, A, R>(&mut self, name: K, _function: F) -> Result<()>
where K: Into<Index>, F: Fn(&'lua Lua, A) -> Result<R> + MaybeSend + 'static, A: FromLuaMulti<'lua> + TypedMultiValue, R: IntoLuaMulti<'lua> + TypedMultiValue,

Typed variant of add_function only collecting the type information
Source§

fn add_function_with<K, F, A, R, G>( &mut self, name: K, _function: F, generator: G, ) -> Result<()>
where K: Into<Index>, F: Fn(&'lua Lua, A) -> Result<R> + MaybeSend + 'static, A: FromLuaMulti<'lua> + TypedMultiValue, R: IntoLuaMulti<'lua> + TypedMultiValue, G: Fn(&mut FunctionBuilder<A, R>),

Typed variant of add_function only collecting the type information Read more
Source§

fn add_meta_function<K, F, A, R>(&mut self, name: K, _function: F) -> Result<()>
where K: Into<Index>, F: Fn(&'lua Lua, A) -> Result<R> + MaybeSend + 'static, A: FromLuaMulti<'lua> + TypedMultiValue, R: IntoLuaMulti<'lua> + TypedMultiValue,

Typed variant of add_meta_function only collecting the type information
Source§

fn add_meta_function_with<K, F, A, R, G>( &mut self, name: K, _function: F, generator: G, ) -> Result<()>
where K: Into<Index>, F: Fn(&'lua Lua, A) -> Result<R> + MaybeSend + 'static, A: FromLuaMulti<'lua> + TypedMultiValue, R: IntoLuaMulti<'lua> + TypedMultiValue, G: Fn(&mut FunctionBuilder<A, R>),

Typed variant of add_meta_function only collecting the type information Read more
Source§

fn add_method<K, F, A, R>(&mut self, name: K, _function: F) -> Result<()>
where K: Into<Index>, F: Fn(&'lua Lua, Table<'_>, A) -> Result<R> + MaybeSend + 'static, A: FromLuaMulti<'lua> + TypedMultiValue, R: IntoLuaMulti<'lua> + TypedMultiValue,

Typed variant of add_method only collecting the type information
Source§

fn add_method_with<K, F, A, R, G>( &mut self, name: K, _function: F, generator: G, ) -> Result<()>
where K: Into<Index>, F: Fn(&'lua Lua, Table<'_>, A) -> Result<R> + MaybeSend + 'static, A: FromLuaMulti<'lua> + TypedMultiValue, R: IntoLuaMulti<'lua> + TypedMultiValue, G: Fn(&mut FunctionBuilder<A, R>),

Typed variant of add_method only collecting the type information Read more
Source§

fn add_meta_method<K, F, A, R>(&mut self, name: K, _function: F) -> Result<()>
where K: Into<Index>, F: Fn(&'lua Lua, Table<'_>, A) -> Result<R> + MaybeSend + 'static, A: FromLuaMulti<'lua> + TypedMultiValue, R: IntoLuaMulti<'lua> + TypedMultiValue,

Typed variant of add_meta_method only collecting the type information
Source§

fn add_meta_method_with<K, F, A, R, G>( &mut self, name: K, _function: F, generator: G, ) -> Result<()>
where K: Into<Index>, F: Fn(&'lua Lua, Table<'_>, A) -> Result<R> + MaybeSend + 'static, A: FromLuaMulti<'lua> + TypedMultiValue, R: IntoLuaMulti<'lua> + TypedMultiValue, G: Fn(&mut FunctionBuilder<A, R>),

Typed variant of add_meta_method only collecting the type information Read more
Source§

impl Eq for TypedModuleBuilder

Source§

impl StructuralPartialEq for TypedModuleBuilder

Auto Trait Implementations§

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,