Skip to main content

TypedClassBuilder

Struct TypedClassBuilder 

Source
pub struct TypedClassBuilder {
    pub typed_class: TypedClass,
    /* private fields */
}
Expand description

Type information for a lua class. This happens to be a TypedUserData

Fields§

§typed_class: TypedClass

Implementations§

Source§

impl TypedClassBuilder

Source

pub fn new<T: TypedUserData>() -> Self

Source

pub fn build(self) -> TypedClass

Source

pub fn skip_field(self, idx: impl Into<Index>) -> Self

Skip/Remove a field field from the class definition

Source

pub fn skip_method(self, idx: impl Into<Index>) -> Self

Skip/Remove a method from the class definition

Source

pub fn skip_meta_method(self, idx: impl Into<Index>) -> Self

Skip/Remove a meta method from the class definition

Source

pub fn skip_function(self, idx: impl Into<Index>) -> Self

Skip/Remove a function from the class definition

Source

pub fn skip_meta_function(self, idx: impl Into<Index>) -> Self

Skip/Remove a meta function from the class definition

Source

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(), format!("A message for {NAME}"));
Source

pub fn static_field<V>( self, key: impl Into<Index>, value: V, doc: impl IntoDocComment, ) -> Self
where V: Typed + IntoLua,

Source

pub fn inherit(self, parent: &TypedClass) -> Self

Source

pub fn function<Params, Returns>( self, key: impl Into<Index>, 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::{TypedClassBuilder, Type};

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

pub fn method<Params, Returns>( self, key: impl Into<Index>, 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::{TypedClassBuilder, Type};

TypedClassBuilder::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_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(), format!("A message for {NAME}"));
Source

pub fn meta_function<Params, Returns>( self, key: impl Into<Index>, 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::{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", ());
Source

pub fn meta_method<Params, Returns>( self, key: impl Into<Index>, 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::{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", ());
Source

pub fn derive(self, parent: impl Display) -> Self

Add a child class that this class derives

Trait Implementations§

Source§

impl Clone for TypedClassBuilder

Source§

fn clone(&self) -> TypedClassBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TypedClassBuilder

Source§

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

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

impl Default for TypedClassBuilder

Source§

fn default() -> TypedClassBuilder

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

impl From<TypedClassBuilder> for Type

Source§

fn from(value: TypedClassBuilder) -> Self

Converts to this type from the input type.
Source§

impl<T: TypedUserData> TypedDataDocumentation<T> for TypedClassBuilder

Source§

fn add(&mut self, doc: &str) -> &mut Self

Source§

impl<T: TypedUserData> TypedDataFields<T> for TypedClassBuilder

Source§

fn document(&mut self, doc: impl IntoDocComment) -> &mut Self

Adds documentation to the next field that gets added
Source§

fn coerce(&mut self, ty: impl Into<Type>) -> &mut Self

Adds a type to the queued overrides. Read more
Source§

fn add_field<V>(&mut self, name: impl Into<String>, value: V)
where V: IntoLua + Clone + 'static + Typed,

Typed version of add_field
Source§

fn add_field_function_set<S, A, F>(&mut self, name: S, _: F)
where S: Into<String>, A: FromLua + Typed, F: 'static + MaybeSend + FnMut(&Lua, AnyUserData, A) -> Result<()>,

Typed version of add_field_function_set
Source§

fn add_field_function_get<S, R, F>(&mut self, name: S, _: F)
where S: Into<String>, R: IntoLua + Typed, F: 'static + MaybeSend + Fn(&Lua, AnyUserData) -> Result<R>,

Typed version of add_field_function_get
Source§

fn add_field_function_get_set<S, R, A, GET, SET>( &mut self, name: S, _: GET, _: SET, )
where S: Into<String>, R: IntoLua + Typed, A: FromLua + Typed, GET: 'static + MaybeSend + Fn(&Lua, AnyUserData) -> Result<R>, SET: 'static + MaybeSend + Fn(&Lua, AnyUserData, A) -> Result<()>,

Typed version of add_field_function_get and add_field_function_set combined
Source§

fn add_field_method_set<S, A, M>(&mut self, name: S, _: M)
where S: Into<String>, A: FromLua + Typed, M: 'static + MaybeSend + FnMut(&Lua, &mut T, A) -> Result<()>,

Typed version of dd_field_method_set
Source§

fn add_field_method_get<S, R, M>(&mut self, name: S, _: M)
where S: Into<String>, R: IntoLua + Typed, M: 'static + MaybeSend + Fn(&Lua, &T) -> Result<R>,

Typed version of add_field_method_get
Source§

fn add_field_method_get_set<S, R, A, GET, SET>( &mut self, name: S, _: GET, _: SET, )
where S: Into<String>, R: IntoLua + Typed, A: FromLua + Typed, GET: 'static + MaybeSend + Fn(&Lua, &T) -> Result<R>, SET: 'static + MaybeSend + Fn(&Lua, &mut T, A) -> Result<()>,

Typed version of add_field_method_get and add_field_method_set combined
Source§

fn add_meta_field<V>(&mut self, meta: impl Into<String>, value: V)
where V: IntoLua + Typed + 'static,

Typed version of add_meta_field
Source§

fn add_meta_field_with<R, F>(&mut self, meta: impl Into<String>, _: F)
where F: 'static + MaybeSend + Fn(&Lua) -> Result<R>, R: IntoLua + Typed,

Typed version of add_meta_field
Source§

impl<T: TypedUserData> TypedDataMethods<T> for TypedClassBuilder

Source§

fn document(&mut self, doc: impl IntoDocComment) -> &mut Self

Adds documentation to the next method/function that gets added
Source§

fn param(&mut self, name: impl Display, doc: impl IntoDocComment) -> &mut Self

Adds a param name and doc comment to the next method/function that gets added. Read more
Source§

fn param_as( &mut self, ty: impl Into<Type>, name: impl Display, doc: impl IntoDocComment, ) -> &mut Self

Adds a param name and doc comment to the next method/function that gets added. Will also add an override type to the param. Read more
Source§

fn ret(&mut self, doc: impl IntoDocComment) -> &mut Self

Adds a return doc comment to the next method/function that gets added. Read more
Source§

fn ret_as(&mut self, ty: impl Into<Type>, doc: impl IntoDocComment) -> &mut Self

Adds a return doc comment to the next method/function that gets added. Will also add an override type to the return. Read more
Source§

fn index<I: Typed>(&mut self, idx: isize, doc: impl IntoDocComment) -> &mut Self

Adds an index field with a type and doc comment to the class definition
Source§

fn index_as( &mut self, idx: isize, ty: impl Into<Type>, doc: impl IntoDocComment, ) -> &mut Self

Adds an index field with a type and doc comment to the class definition
Source§

fn add_method<S, A, R, M>(&mut self, name: S, _: M)
where S: Into<String>, A: FromLuaMulti + TypedMultiValue, R: IntoLuaMulti + TypedMultiValue, M: 'static + MaybeSend + Fn(&Lua, &T, A) -> Result<R>,

Exposes a method to lua
Source§

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

Exposes a function to lua (its a method that does not take Self)
Source§

fn add_method_mut<S, A, R, M>(&mut self, name: S, _: M)

Exposes a method to lua that has a mutable reference to Self
Source§

fn add_meta_method<A, R, M>(&mut self, meta: impl Into<String>, _: M)
where A: FromLuaMulti + TypedMultiValue, R: IntoLuaMulti + TypedMultiValue, M: 'static + MaybeSend + Fn(&Lua, &T, A) -> Result<R>,

Exposes a meta method to lua http://lua-users.org/wiki/MetatableEvents
Source§

fn add_async_method<S: Into<String>, A, R, M, MR>(&mut self, name: S, _: M)
where T: 'static, M: Fn(Lua, UserDataRef<T>, A) -> MR + MaybeSend + 'static, A: FromLuaMulti + TypedMultiValue, MR: Future<Output = Result<R>> + MaybeSend + 'static, R: IntoLuaMulti + TypedMultiValue,

exposes an async method to lua
Source§

fn add_async_method_mut<S: Into<String>, A, R, M, MR>( &mut self, name: S, _method: M, )
where T: 'static, M: Fn(Lua, UserDataRefMut<T>, A) -> MR + MaybeSend + 'static, A: FromLuaMulti + TypedMultiValue, MR: Future<Output = Result<R>> + MaybeSend + 'static, R: IntoLuaMulti + TypedMultiValue,

exposes an async method to lua
Source§

fn add_function_mut<S, A, R, F>(&mut self, name: S, _: F)
where S: Into<String>, A: FromLuaMulti + TypedMultiValue, R: IntoLuaMulti + TypedMultiValue, F: 'static + MaybeSend + FnMut(&Lua, A) -> Result<R>,

Exposes a mutable function to lua
Source§

fn add_meta_function<A, R, F>(&mut self, meta: impl Into<String>, _: F)
where A: FromLuaMulti + TypedMultiValue, R: IntoLuaMulti + TypedMultiValue, F: 'static + MaybeSend + Fn(&Lua, A) -> Result<R>,

Exposes a meta function to lua http://lua-users.org/wiki/MetatableEvents
Source§

fn add_async_function<S, A, R, F, FR>(&mut self, name: S, _: F)
where S: Into<String>, A: FromLuaMulti + TypedMultiValue, R: IntoLuaMulti + TypedMultiValue, F: 'static + MaybeSend + Fn(Lua, A) -> FR, FR: 'static + MaybeSend + Future<Output = Result<R>>,

exposes an async function to lua
Source§

fn add_meta_method_mut<A, R, M>(&mut self, meta: impl Into<String>, _: M)

Exposes a meta and mutable method to lua http://lua-users.org/wiki/MetatableEvents
Source§

fn add_meta_function_mut<A, R, F>(&mut self, meta: impl Into<String>, _: F)
where A: FromLuaMulti + TypedMultiValue, R: IntoLuaMulti + TypedMultiValue, F: 'static + MaybeSend + FnMut(&Lua, A) -> Result<R>,

Exposes a meta and mutable function to lua http://lua-users.org/wiki/MetatableEvents

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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,

Source§

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