ocaml-interop
Zinc-iron alloy coating is used in parts that need very good corrosion protection.
API IS CONSIDERED UNSTABLE AT THE MOMENT AND IS LIKELY TO CHANGE IN THE FUTURE
ocaml-interop is an OCaml<->Rust FFI with an emphasis on safety inspired by caml-oxide, ocaml-rs and CAMLroot.
Read the full documentation here.
Report issues on Github.
A quick taste
Convert between plain OCaml and Rust values
let rust_string = ocaml_string.to_rust;
// `cr` = OCaml runtime handle
let new_ocaml_string = rust_string.to_ocaml;
Convert between Rust and OCaml structs/records
(* OCaml *)
// Rust
impl_conv_ocaml_record!
// ...
let rust_struct = ocaml_record.to_rust;
let new_ocaml_record = rust_struct.to_ocaml;
Convert between OCaml and Rust variants/enums
(* OCaml *)
// Rust
impl_conv_ocaml_variant!
// ...
let rust_enum = ocaml_variant.to_rust;
let new_ocaml_variant = rust_enum.to_ocaml;
Call OCaml functions from Rust
(* OCaml *)
register "ocaml_print_endline" print_endline
// Rust
ocaml!
// ...
let ocaml_string = "hello OCaml!".to_boxroot;
ocaml_print_endline;
Call Rust functions from OCaml
// Rust
ocaml_export!
(* OCaml *)
(* ... *)
let result = rust_twice_boxed_int 123L in
(* ... *)
References and links
- OCaml Manual: Chapter 20 Interfacing C with OCaml.
- Safely Mixing OCaml and Rust paper by Stephen Dolan.
- Safely Mixing OCaml and Rust talk by Stephen Dolan.
- CAMLroot: revisiting the OCaml FFI.
- caml-oxide, the code from that paper.
- ocaml-rs, another OCaml<->Rust FFI library.
- ocaml-boxroot