[−][src]Macro ocaml_interop::ocaml_alloc_variant
Allocates an OCaml variant, mapped from a Rust enum.
The match in this conversion is exhaustive, and requires that every enum case is covered.
It is important that the order of the fields remains the same as in the OCaml type declaration.
Examples
enum Movement { StepLeft, StepRight, Rotate(f64), } // Assuming an OCaml type declaration like: // // type movement = // | StepLeft // | StepRight // | Rotate of float // // NOTE: What is important is the order of the tags, not their names. let movement = Movement::Rotate(180.0); let ocaml_movement: OCaml<Movement> = ocaml_alloc_variant! { cr, movement => { Movement::StepLeft, Movement::StepRight, // Tag field names are mandatory Movement::Rotate(rotation: OCamlFloat), } }; // ...