Note: ocaml-rs
is still experimental, please report any issues on github
ocaml-rs
allows for OCaml extensions to be written directly in Rust with no C stubs. It was forked from raml with the goal of creating a safer, high-level interface.
#[macro_use]
use ocaml;
use ocaml::ToValue;
caml!(ml_beef, |parameter|, <local>, {
let i = parameter.i32_val();
let res = 0xbeef * i;
println!("about to return 0x{:x} to OCaml runtime", res);
local = res.to_value();
} -> local);
This will take care of all the OCaml garbage collector related bookkeeping (CAMLparam, CAMLlocal and CAMLreturn)
For a working example see ocaml-vec or ./examples/rust
and ./examples/ocaml