macro_rules! impl_from_ocaml_record { ($ocaml_typ:ident => $rust_typ:ident { $($field:ident : $ocaml_field_typ:ty),+ $(,)? }) => { ... }; ($both_typ:ident { $($t:tt)* }) => { ... }; ($ocaml_typ:ident => $rust_typ:ident ( $($field:ident : $ocaml_field_typ:ty),+ $(,)? )) => { ... }; ($both_typ:ident ( $($t:tt)* )) => { ... }; }
Expand description
Implements FromOCaml
for mapping an OCaml record into a Rust record.
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.
impl_from_ocaml_record! {
// Optionally, if Rust and OCaml types don't match:
// OCamlType => RustType { ... }
MyStruct {
int_field: OCamlInt,
string_field: String,
}
}