pub trait LuaEnum {
// Required methods
fn variants() -> &'static [(&'static str, i64)];
fn enum_name() -> &'static str;
}Expand description
Trait for Rust enums that can be exported to Lua as a table of constants.
Automatically implemented by #[derive(LuaUserData)] on C-like enums
(enums with no data fields). Each variant becomes a key-value pair in
a Lua table.
§Example
ⓘ
#[derive(LuaUserData)]
enum Color {
Red, // 0
Green, // 1
Blue, // 2
}
// With explicit discriminants:
#[derive(LuaUserData)]
enum HttpStatus {
Ok = 200,
NotFound = 404,
ServerError = 500,
}
// Register in Lua:
vm.register_enum::<Color>("Color")?;
// Lua: Color.Red == 0, Color.Green == 1, Color.Blue == 2Required Methods§
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.