pub trait UserDataMethods<T> {
Show 16 methods
// Required methods
fn add_method<M, A, R>(&mut self, name: impl Into<String>, method: M)
where M: Fn(&Lua, &T, A) -> Result<R> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti;
fn add_method_mut<M, A, R>(&mut self, name: impl Into<String>, method: M)
where M: FnMut(&Lua, &mut T, A) -> Result<R> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti;
fn add_async_method<M, A, MR, R>(
&mut self,
name: impl Into<String>,
method: M,
)
where T: 'static,
M: Fn(Lua, UserDataRef<T>, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti,
MR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti;
fn add_async_method_mut<M, A, MR, R>(
&mut self,
name: impl Into<String>,
method: M,
)
where T: 'static,
M: Fn(Lua, UserDataRefMut<T>, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti,
MR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti;
fn add_function<F, A, R>(&mut self, name: impl Into<String>, function: F)
where F: Fn(&Lua, A) -> Result<R> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti;
fn add_function_mut<F, A, R>(
&mut self,
name: impl Into<String>,
function: F,
)
where F: FnMut(&Lua, A) -> Result<R> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti;
fn add_async_function<F, A, FR, R>(
&mut self,
name: impl Into<String>,
function: F,
)
where F: Fn(Lua, A) -> FR + MaybeSend + 'static,
A: FromLuaMulti,
FR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti;
fn add_meta_method<M, A, R>(&mut self, name: impl Into<String>, method: M)
where M: Fn(&Lua, &T, A) -> Result<R> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti;
fn add_meta_method_mut<M, A, R>(
&mut self,
name: impl Into<String>,
method: M,
)
where M: FnMut(&Lua, &mut T, A) -> Result<R> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti;
fn add_async_meta_method<M, A, MR, R>(
&mut self,
name: impl Into<String>,
method: M,
)
where T: 'static,
M: Fn(Lua, UserDataRef<T>, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti,
MR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti;
fn add_async_meta_method_mut<M, A, MR, R>(
&mut self,
name: impl Into<String>,
method: M,
)
where T: 'static,
M: Fn(Lua, UserDataRefMut<T>, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti,
MR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti;
fn add_meta_function<F, A, R>(
&mut self,
name: impl Into<String>,
function: F,
)
where F: Fn(&Lua, A) -> Result<R> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti;
fn add_meta_function_mut<F, A, R>(
&mut self,
name: impl Into<String>,
function: F,
)
where F: FnMut(&Lua, A) -> Result<R> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti;
fn add_async_meta_function<F, A, FR, R>(
&mut self,
name: impl Into<String>,
function: F,
)
where F: Fn(Lua, A) -> FR + MaybeSend + 'static,
A: FromLuaMulti,
FR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti;
// Provided methods
fn add_method_once<M, A, R>(&mut self, name: impl Into<String>, method: M)
where T: 'static,
M: Fn(&Lua, T, A) -> Result<R> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti { ... }
fn add_async_method_once<M, A, MR, R>(
&mut self,
name: impl Into<String>,
method: M,
)
where T: 'static,
M: Fn(Lua, T, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti,
MR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti { ... }
}Expand description
Method registry for UserData implementors.
Required Methods§
Sourcefn add_method<M, A, R>(&mut self, name: impl Into<String>, method: M)
fn add_method<M, A, R>(&mut self, name: impl Into<String>, method: M)
Add a regular method which accepts a &T as the first parameter.
Regular methods are implemented by overriding the __index metamethod and returning the
accessed method. This allows them to be used with the expected userdata:method() syntax.
If add_meta_method is used to set the __index metamethod, the __index metamethod will
be used as a fall-back if no regular method is found.
Sourcefn add_method_mut<M, A, R>(&mut self, name: impl Into<String>, method: M)where
M: FnMut(&Lua, &mut T, A) -> Result<R> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti,
fn add_method_mut<M, A, R>(&mut self, name: impl Into<String>, method: M)where
M: FnMut(&Lua, &mut T, A) -> Result<R> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti,
Add a regular method which accepts a &mut T as the first parameter.
Refer to add_method for more information about the implementation.
Sourcefn add_async_method<M, A, MR, R>(&mut self, name: impl Into<String>, method: M)where
T: 'static,
M: Fn(Lua, UserDataRef<T>, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti,
MR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti,
Available on crate feature async only.
fn add_async_method<M, A, MR, R>(&mut self, name: impl Into<String>, method: M)where
T: 'static,
M: Fn(Lua, UserDataRef<T>, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti,
MR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti,
async only.Add an async method which accepts a &T as the first parameter and returns Future.
Refer to add_method for more information about the implementation.
Sourcefn add_async_method_mut<M, A, MR, R>(
&mut self,
name: impl Into<String>,
method: M,
)where
T: 'static,
M: Fn(Lua, UserDataRefMut<T>, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti,
MR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti,
Available on crate feature async only.
fn add_async_method_mut<M, A, MR, R>(
&mut self,
name: impl Into<String>,
method: M,
)where
T: 'static,
M: Fn(Lua, UserDataRefMut<T>, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti,
MR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti,
async only.Add an async method which accepts a &mut T as the first parameter and returns Future.
Refer to add_method for more information about the implementation.
Sourcefn add_function<F, A, R>(&mut self, name: impl Into<String>, function: F)
fn add_function<F, A, R>(&mut self, name: impl Into<String>, function: F)
Add a regular method as a function which accepts generic arguments.
The first argument will be a AnyUserData of type T if the method is called with Lua
method syntax: my_userdata:my_method(arg1, arg2), or it is passed in as the first
argument: my_userdata.my_method(my_userdata, arg1, arg2).
Sourcefn add_function_mut<F, A, R>(&mut self, name: impl Into<String>, function: F)
fn add_function_mut<F, A, R>(&mut self, name: impl Into<String>, function: F)
Add a regular method as a mutable function which accepts generic arguments.
This is a version of add_function that accepts a FnMut argument.
Sourcefn add_async_function<F, A, FR, R>(
&mut self,
name: impl Into<String>,
function: F,
)where
F: Fn(Lua, A) -> FR + MaybeSend + 'static,
A: FromLuaMulti,
FR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti,
Available on crate feature async only.
fn add_async_function<F, A, FR, R>(
&mut self,
name: impl Into<String>,
function: F,
)where
F: Fn(Lua, A) -> FR + MaybeSend + 'static,
A: FromLuaMulti,
FR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti,
async only.Add a regular method as an async function which accepts generic arguments and returns
Future.
This is an async version of add_function.
Sourcefn add_meta_method<M, A, R>(&mut self, name: impl Into<String>, method: M)
fn add_meta_method<M, A, R>(&mut self, name: impl Into<String>, method: M)
Add a metamethod which accepts a &T as the first parameter.
§Note
This can cause an error with certain binary metamethods that can trigger if only the right
side has a metatable. To prevent this, use add_meta_function.
Sourcefn add_meta_method_mut<M, A, R>(&mut self, name: impl Into<String>, method: M)where
M: FnMut(&Lua, &mut T, A) -> Result<R> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti,
fn add_meta_method_mut<M, A, R>(&mut self, name: impl Into<String>, method: M)where
M: FnMut(&Lua, &mut T, A) -> Result<R> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti,
Add a metamethod as a function which accepts a &mut T as the first parameter.
§Note
This can cause an error with certain binary metamethods that can trigger if only the right
side has a metatable. To prevent this, use add_meta_function.
Sourcefn add_async_meta_method<M, A, MR, R>(
&mut self,
name: impl Into<String>,
method: M,
)where
T: 'static,
M: Fn(Lua, UserDataRef<T>, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti,
MR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti,
Available on crate feature async and neither crate feature lua51 nor crate feature luau only.
fn add_async_meta_method<M, A, MR, R>(
&mut self,
name: impl Into<String>,
method: M,
)where
T: 'static,
M: Fn(Lua, UserDataRef<T>, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti,
MR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti,
async and neither crate feature lua51 nor crate feature luau only.Add an async metamethod which accepts a &T as the first parameter and returns Future.
This is an async version of add_meta_method.
Sourcefn add_async_meta_method_mut<M, A, MR, R>(
&mut self,
name: impl Into<String>,
method: M,
)where
T: 'static,
M: Fn(Lua, UserDataRefMut<T>, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti,
MR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti,
Available on crate feature async only.
fn add_async_meta_method_mut<M, A, MR, R>(
&mut self,
name: impl Into<String>,
method: M,
)where
T: 'static,
M: Fn(Lua, UserDataRefMut<T>, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti,
MR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti,
async only.Add an async metamethod which accepts a &mut T as the first parameter and returns
Future.
This is an async version of add_meta_method_mut.
Sourcefn add_meta_function<F, A, R>(&mut self, name: impl Into<String>, function: F)
fn add_meta_function<F, A, R>(&mut self, name: impl Into<String>, function: F)
Add a metamethod which accepts generic arguments.
Metamethods for binary operators can be triggered if either the left or right argument to
the binary operator has a metatable, so the first argument here is not necessarily a
userdata of type T.
Sourcefn add_meta_function_mut<F, A, R>(
&mut self,
name: impl Into<String>,
function: F,
)
fn add_meta_function_mut<F, A, R>( &mut self, name: impl Into<String>, function: F, )
Add a metamethod as a mutable function which accepts generic arguments.
This is a version of add_meta_function that accepts a FnMut argument.
Sourcefn add_async_meta_function<F, A, FR, R>(
&mut self,
name: impl Into<String>,
function: F,
)where
F: Fn(Lua, A) -> FR + MaybeSend + 'static,
A: FromLuaMulti,
FR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti,
Available on crate feature async and neither crate feature lua51 nor crate feature luau only.
fn add_async_meta_function<F, A, FR, R>(
&mut self,
name: impl Into<String>,
function: F,
)where
F: Fn(Lua, A) -> FR + MaybeSend + 'static,
A: FromLuaMulti,
FR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti,
async and neither crate feature lua51 nor crate feature luau only.Add a metamethod which accepts generic arguments and returns Future.
This is an async version of add_meta_function.
Provided Methods§
Sourcefn add_method_once<M, A, R>(&mut self, name: impl Into<String>, method: M)where
T: 'static,
M: Fn(&Lua, T, A) -> Result<R> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti,
fn add_method_once<M, A, R>(&mut self, name: impl Into<String>, method: M)where
T: 'static,
M: Fn(&Lua, T, A) -> Result<R> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti,
Add a method which accepts T as the first parameter.
The userdata T will be moved out of the userdata container. This is useful for
methods that need to consume the userdata.
The method can be called only once per userdata instance, subsequent calls will result in a
Error::UserDataDestructed error.
Sourcefn add_async_method_once<M, A, MR, R>(
&mut self,
name: impl Into<String>,
method: M,
)where
T: 'static,
M: Fn(Lua, T, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti,
MR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti,
Available on crate feature async only.
fn add_async_method_once<M, A, MR, R>(
&mut self,
name: impl Into<String>,
method: M,
)where
T: 'static,
M: Fn(Lua, T, A) -> MR + MaybeSend + 'static,
A: FromLuaMulti,
MR: Future<Output = Result<R>> + MaybeSend + 'static,
R: IntoLuaMulti,
async only.Add an async method which accepts a T as the first parameter and returns Future.
The userdata T will be moved out of the userdata container. This is useful for
methods that need to consume the userdata.
The method can be called only once per userdata instance, subsequent calls will result in a
Error::UserDataDestructed error.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.