Macro ocaml_interop::ocaml_unpack_record [−][src]
macro_rules! ocaml_unpack_record { ($var:ident => $cons:ident { $($field:ident : $ocaml_typ:ty),+ $(,)? }) => { ... }; ($var:ident => $cons:ident ( $($field:ident : $ocaml_typ:ty),+ $(,)? )) => { ... }; }
Expand description
Unpacks an OCaml record into a Rust record.
This macro works on OCaml
<'gc, T>
values.
It is important that the order of the fields remains the same as in the OCaml type declaration.
Examples
struct MyStruct { int_field: i64, string_field: String, } // Assuming an OCaml record declaration like: // // type my_struct = { // int_field: int; // string_field: string; // } // // NOTE: What is important is the order of the fields, not their names. let ocaml_struct_root = make_mystruct(cr, &OCaml::unit()); let ocaml_struct = cr.get(&ocaml_struct_root); let my_struct = ocaml_unpack_record! { // value => RustConstructor { field: OCamlType, ... } ocaml_struct => MyStruct { int_field: OCamlInt, string_field: String, } }; // ...