Macro ocaml_interop::impl_from_ocaml_variant [−][src]
macro_rules! impl_from_ocaml_variant {
($ocaml_typ : ty => $rust_typ : ty { $($t : tt) * }) => { ... };
($both_typ : ty { $($t : tt) * }) => { ... };
}
Expand description
Implements FromOCaml
for mapping an OCaml variant into a Rust enum.
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.
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),
}
}