pub trait UserDataFields<T> {
// Required methods
fn add_field<V>(&mut self, name: impl ToString, value: V)
where V: IntoLua + 'static;
fn add_field_method_get<M, R>(&mut self, name: impl ToString, method: M)
where M: Fn(&Lua, &T) -> Result<R> + MaybeSend + 'static,
R: IntoLua;
fn add_field_method_set<M, A>(&mut self, name: impl ToString, method: M)
where M: FnMut(&Lua, &mut T, A) -> Result<()> + MaybeSend + 'static,
A: FromLua;
fn add_field_function_get<F, R>(&mut self, name: impl ToString, function: F)
where F: Fn(&Lua, AnyUserData) -> Result<R> + MaybeSend + 'static,
R: IntoLua;
fn add_field_function_set<F, A>(&mut self, name: impl ToString, function: F)
where F: FnMut(&Lua, AnyUserData, A) -> Result<()> + MaybeSend + 'static,
A: FromLua;
fn add_meta_field<V>(&mut self, name: impl ToString, value: V)
where V: IntoLua + 'static;
fn add_meta_field_with<F, R>(&mut self, name: impl ToString, f: F)
where F: FnOnce(&Lua) -> Result<R> + 'static,
R: IntoLua;
}
Expand description
Field registry for UserData
implementors.
Required Methods§
Sourcefn add_field<V>(&mut self, name: impl ToString, value: V)where
V: IntoLua + 'static,
fn add_field<V>(&mut self, name: impl ToString, value: V)where
V: IntoLua + 'static,
Add a static field to the UserData
.
Static fields are implemented by updating the __index
metamethod and returning the
accessed field. This allows them to be used with the expected userdata.field
syntax.
Static fields are usually shared between all instances of the UserData
of the same type.
If add_meta_method
is used to set the __index
metamethod, it will
be used as a fall-back if no regular field or method are found.
Sourcefn add_field_method_get<M, R>(&mut self, name: impl ToString, method: M)
fn add_field_method_get<M, R>(&mut self, name: impl ToString, method: M)
Add a regular field getter as a method which accepts a &T
as the parameter.
Regular field getters are implemented by overriding the __index
metamethod and returning
the accessed field. This allows them to be used with the expected userdata.field
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 field or method are found.
Sourcefn add_field_method_set<M, A>(&mut self, name: impl ToString, method: M)
fn add_field_method_set<M, A>(&mut self, name: impl ToString, method: M)
Add a regular field setter as a method which accepts a &mut T
as the first parameter.
Regular field setters are implemented by overriding the __newindex
metamethod and setting
the accessed field. This allows them to be used with the expected userdata.field = value
syntax.
If add_meta_method
is used to set the __newindex
metamethod, the __newindex
metamethod
will be used as a fall-back if no regular field is found.
Sourcefn add_field_function_get<F, R>(&mut self, name: impl ToString, function: F)
fn add_field_function_get<F, R>(&mut self, name: impl ToString, function: F)
Add a regular field getter as a function which accepts a generic AnyUserData
of type T
argument.
Sourcefn add_field_function_set<F, A>(&mut self, name: impl ToString, function: F)
fn add_field_function_set<F, A>(&mut self, name: impl ToString, function: F)
Add a regular field setter as a function which accepts a generic AnyUserData
of type T
first argument.
Sourcefn add_meta_field<V>(&mut self, name: impl ToString, value: V)where
V: IntoLua + 'static,
fn add_meta_field<V>(&mut self, name: impl ToString, value: V)where
V: IntoLua + 'static,
Sourcefn add_meta_field_with<F, R>(&mut self, name: impl ToString, f: F)
fn add_meta_field_with<F, R>(&mut self, name: impl ToString, f: F)
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.