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
 
impl TypedModuleBuilder
pub fn new<M: TypedModule>() -> Result<Self>
pub fn is_empty(&self) -> bool
pub fn is_meta_empty(&self) -> bool
Sourcepub fn field<S: AsRef<str>>(
    self,
    name: impl AsRef<str>,
    ty: Type,
    doc: impl IntoDocComment,
) -> Self
 
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}"))Sourcepub fn function<Params, Returns>(
    self,
    name: impl AsRef<str>,
    doc: impl IntoDocComment,
) -> Selfwhere
    Params: TypedMultiValue,
    Returns: TypedMultiValue,
 
pub fn function<Params, Returns>(
    self,
    name: impl AsRef<str>,
    doc: impl IntoDocComment,
) -> Selfwhere
    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", ())Sourcepub fn function_with<Params, Returns, F, R>(
    self,
    name: impl AsRef<str>,
    doc: impl IntoDocComment,
    generator: F,
) -> Selfwhere
    Params: TypedMultiValue,
    Returns: TypedMultiValue,
    F: Fn(&mut FunctionBuilder<Params, Returns>) -> R,
    R: Any,
 
pub fn function_with<Params, Returns, F, R>(
    self,
    name: impl AsRef<str>,
    doc: impl IntoDocComment,
    generator: F,
) -> Selfwhere
    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"))
    })Sourcepub fn method<Params, Returns>(
    self,
    name: impl AsRef<str>,
    doc: impl IntoDocComment,
) -> Selfwhere
    Params: TypedMultiValue,
    Returns: TypedMultiValue,
 
pub fn method<Params, Returns>(
    self,
    name: impl AsRef<str>,
    doc: impl IntoDocComment,
) -> Selfwhere
    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", ())Sourcepub fn method_with<Params, Returns, F, R>(
    self,
    name: impl AsRef<str>,
    doc: impl IntoDocComment,
    generator: F,
) -> Selfwhere
    Params: TypedMultiValue,
    Returns: TypedMultiValue,
    F: Fn(&mut FunctionBuilder<Params, Returns>) -> R,
    R: Any,
 
pub fn method_with<Params, Returns, F, R>(
    self,
    name: impl AsRef<str>,
    doc: impl IntoDocComment,
    generator: F,
) -> Selfwhere
    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"))
    })Sourcepub fn meta_field<S: AsRef<str>>(
    self,
    name: impl AsRef<str>,
    ty: Type,
    doc: impl IntoDocComment,
) -> Self
 
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}"))Sourcepub fn meta_function<Params, Returns>(
    self,
    name: impl AsRef<str>,
    doc: impl IntoDocComment,
) -> Selfwhere
    Params: TypedMultiValue,
    Returns: TypedMultiValue,
 
pub fn meta_function<Params, Returns>(
    self,
    name: impl AsRef<str>,
    doc: impl IntoDocComment,
) -> Selfwhere
    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", ())Sourcepub fn meta_function_with<Params, Returns, F, R>(
    self,
    name: impl AsRef<str>,
    doc: impl IntoDocComment,
    generator: F,
) -> Selfwhere
    F: Fn(&mut FunctionBuilder<Params, Returns>) -> R,
    R: Any,
    Params: TypedMultiValue,
    Returns: TypedMultiValue,
 
pub fn meta_function_with<Params, Returns, F, R>(
    self,
    name: impl AsRef<str>,
    doc: impl IntoDocComment,
    generator: F,
) -> Selfwhere
    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"))
    })Sourcepub fn meta_method<Params, Returns>(
    self,
    name: impl AsRef<str>,
    doc: impl IntoDocComment,
) -> Selfwhere
    Params: TypedMultiValue,
    Returns: TypedMultiValue,
 
pub fn meta_method<Params, Returns>(
    self,
    name: impl AsRef<str>,
    doc: impl IntoDocComment,
) -> Selfwhere
    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", ())Sourcepub fn meta_method_with<Params, Returns, F, R>(
    self,
    name: impl AsRef<str>,
    doc: impl IntoDocComment,
    generator: F,
) -> Selfwhere
    F: Fn(&mut FunctionBuilder<Params, Returns>) -> R,
    R: Any,
    Params: TypedMultiValue,
    Returns: TypedMultiValue,
 
pub fn meta_method_with<Params, Returns, F, R>(
    self,
    name: impl AsRef<str>,
    doc: impl IntoDocComment,
    generator: F,
) -> Selfwhere
    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
 
impl Clone for TypedModuleBuilder
Source§fn clone(&self) -> TypedModuleBuilder
 
fn clone(&self) -> TypedModuleBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
 
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TypedModuleBuilder
 
impl Debug for TypedModuleBuilder
Source§impl Default for TypedModuleBuilder
 
impl Default for TypedModuleBuilder
Source§fn default() -> TypedModuleBuilder
 
fn default() -> TypedModuleBuilder
Source§impl From<TypedModuleBuilder> for Type
 
impl From<TypedModuleBuilder> for Type
Source§fn from(value: TypedModuleBuilder) -> Self
 
fn from(value: TypedModuleBuilder) -> Self
Source§impl Hash for TypedModuleBuilder
 
impl Hash for TypedModuleBuilder
Source§impl Ord for TypedModuleBuilder
 
impl Ord for TypedModuleBuilder
Source§fn cmp(&self, other: &TypedModuleBuilder) -> Ordering
 
fn cmp(&self, other: &TypedModuleBuilder) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
    Self: Sized,
 
fn max(self, other: Self) -> Selfwhere
    Self: Sized,
Source§impl PartialEq for TypedModuleBuilder
 
impl PartialEq for TypedModuleBuilder
Source§impl PartialOrd for TypedModuleBuilder
 
impl PartialOrd for TypedModuleBuilder
Source§impl<'lua> TypedModuleFields<'lua> for TypedModuleBuilder
 
impl<'lua> TypedModuleFields<'lua> for TypedModuleBuilder
Source§fn document<V: AsRef<str>>(&mut self, doc: V) -> &mut Self
 
fn document<V: AsRef<str>>(&mut self, doc: V) -> &mut Self
add callSource§fn add_module<V>(&mut self, name: impl Into<Index>) -> Result<()>where
    V: TypedModule,
 
fn add_module<V>(&mut self, name: impl Into<Index>) -> Result<()>where
    V: TypedModule,
add_module only collecting the type informationSource§fn add_field<K, V>(&mut self, name: K, _value: V) -> Result<()>
 
fn add_field<K, V>(&mut self, name: K, _value: V) -> Result<()>
add_field only collecting the type informationSource§fn add_meta_field<K, V>(&mut self, name: K, _value: V) -> Result<()>
 
fn add_meta_field<K, V>(&mut self, name: K, _value: V) -> Result<()>
add_meta_field only collecting the type informationSource§impl<'lua> TypedModuleMethods<'lua> for TypedModuleBuilder
 
impl<'lua> TypedModuleMethods<'lua> for TypedModuleBuilder
Source§fn document<V: AsRef<str>>(&mut self, doc: V) -> &mut Self
 
fn document<V: AsRef<str>>(&mut self, doc: V) -> &mut Self
add callSource§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,
 
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,
add_function only collecting the type informationSource§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>),
 
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>),
add_function only collecting the type information Read moreSource§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,
 
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,
add_meta_function only collecting the type informationSource§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>),
 
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>),
add_meta_function only collecting the type information Read moreSource§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,
 
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,
add_method only collecting the type informationSource§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>),
 
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>),
add_method only collecting the type information Read moreSource§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,
 
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,
add_meta_method only collecting the type informationSource§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>),
 
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>),
add_meta_method only collecting the type information Read more