pub struct TypedClassBuilder {
    pub type_doc: Option<Cow<'static, str>>,
    pub fields: BTreeMap<Index, Field>,
    pub static_fields: BTreeMap<Index, Field>,
    pub meta_fields: BTreeMap<Index, Field>,
    pub methods: BTreeMap<Index, Func>,
    pub meta_methods: BTreeMap<Index, Func>,
    pub functions: BTreeMap<Index, Func>,
    pub meta_functions: BTreeMap<Index, Func>,
    /* private fields */
}Expand description
Type information for a lua class. This happens to be a TypedUserData
Fields§
§type_doc: Option<Cow<'static, str>>§fields: BTreeMap<Index, Field>§static_fields: BTreeMap<Index, Field>§meta_fields: BTreeMap<Index, Field>§methods: BTreeMap<Index, Func>§meta_methods: BTreeMap<Index, Func>§functions: BTreeMap<Index, Func>§meta_functions: BTreeMap<Index, Func>Implementations§
Source§impl TypedClassBuilder
 
impl TypedClassBuilder
pub fn new<T: TypedUserData>() -> Self
Sourcepub fn is_meta_empty(&self) -> bool
 
pub fn is_meta_empty(&self) -> bool
Check if any of there are any meta fields, functions, or methods present
Sourcepub fn field(
    self,
    key: impl Into<Index>,
    ty: Type,
    doc: impl IntoDocComment,
) -> Self
 
pub fn field( self, key: impl Into<Index>, 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::{TypedClassBuilder, Type};
static NAME: &str = "mlua_extras";
TypedClassBuilder::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,
    key: impl Into<Index>,
    doc: impl IntoDocComment,
) -> Selfwhere
    Params: TypedMultiValue,
    Returns: TypedMultiValue,
 
pub fn function<Params, Returns>(
    self,
    key: impl Into<Index>,
    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::{TypedClassBuilder, Type};
TypedClassBuilder::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,
    key: impl Into<Index>,
    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,
    key: impl Into<Index>,
    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::{TypedClassBuilder, Type};
TypedClassBuilder::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,
    key: impl Into<Index>,
    doc: impl IntoDocComment,
) -> Selfwhere
    Params: TypedMultiValue,
    Returns: TypedMultiValue,
 
pub fn method<Params, Returns>(
    self,
    key: impl Into<Index>,
    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::{TypedClassBuilder, Type};
TypedClassBuilder::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,
    key: impl Into<Index>,
    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,
    key: impl Into<Index>,
    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::{TypedClassBuilder, Type};
TypedClassBuilder::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(
    self,
    key: impl Into<Index>,
    ty: Type,
    doc: impl IntoDocComment,
) -> Self
 
pub fn meta_field( self, key: impl Into<Index>, 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::{TypedClassBuilder, Type};
static NAME: &str = "mlua_extras";
TypedClassBuilder::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,
    key: impl Into<Index>,
    doc: impl IntoDocComment,
) -> Selfwhere
    Params: TypedMultiValue,
    Returns: TypedMultiValue,
 
pub fn meta_function<Params, Returns>(
    self,
    key: impl Into<Index>,
    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::{TypedClassBuilder, Type};
TypedClassBuilder::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,
    key: impl Into<Index>,
    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,
    key: impl Into<Index>,
    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::{TypedClassBuilder, Type};
TypedClassBuilder::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,
    key: impl Into<Index>,
    doc: impl IntoDocComment,
) -> Selfwhere
    Params: TypedMultiValue,
    Returns: TypedMultiValue,
 
pub fn meta_method<Params, Returns>(
    self,
    key: impl Into<Index>,
    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::{TypedClassBuilder, Type};
static NAME: &str = "mlua_extras";
TypedClassBuilder::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,
    key: impl Into<Index>,
    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,
    key: impl Into<Index>,
    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::{TypedClassBuilder, Type};
TypedClassBuilder::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 TypedClassBuilder
 
impl Clone for TypedClassBuilder
Source§fn clone(&self) -> TypedClassBuilder
 
fn clone(&self) -> TypedClassBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
 
fn clone_from(&mut self, source: &Self)
source. Read more