[−][src]Macro ocaml_interop::impl_from_ocaml_variant
Implements [FromOCaml
] for mapping an OCaml variant into a Rust enum.
It is important that the order 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. impl_from_ocaml_variant! { // Optionally, if Rust and OCaml types don't match: // OCamlType => RustType { ... } Movement { // Alternative: StepLeft => Movement::StepLeft // <anyname> => <build-expr> Movement::StepLeft, Movement::StepRight, // Tag field names are mandatory Movement::Rotate(rotation: OCamlFloat), } }