macro_rules! body {
    ($gc:ident: $code:block) => { ... };
}
Expand description

body! is needed to help the OCaml runtime to manage garbage collection, it should be used to wrap the body of each function exported to OCaml. Panics from Rust code will automatically be unwound/caught here (unless the no-std feature is enabled)

#[no_mangle]
pub unsafe extern "C" fn example(a: ocaml::Value, b: ocaml::Value) -> ocaml::Value {
    ocaml::body!(gc: {
        let a = a.int_val();
        let b = b.int_val();
        ocaml::Value::int(a + b)
    })
}