macro_rules! create_union_mlua {
    ($visibility:vis $(Derives($($derives:ident), +))? enum $type_name:ident = $($sub_types:ident) | +) => { ... };
}
Expand description

Creates a new type that is a union of the types you gave.

It gets translated to a union type in teal and an enum on Rust.

Warning:

teal has a few restrictions on what it finds a valid union types. tealr does NOT check if the types you put in are a valid combination

Example

create_union_mlua!(pub enum YourPublicType = String | f64 | bool);
create_union_mlua!(enum YourType = String | f64 | bool);

It does the conversion by going through the list of possible types and trying to turn the lua value into a Rust type. If the conversion succeeded then it is assumed that the given lua value corresponds to the given rust type

Because of this, it is very important that the Lua -> Rust conversion does as little “type massaging” as possible. As a result, the macro only works with types that implement FromLuaExact as implementing this for a type should mean the conversion rather fails than to try and make it work