ocaml 0.9.1

OCaml bindings for Rust
docs.rs failed to build ocaml-0.9.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: ocaml-1.0.0-beta.5

ocaml-rs - OCaml extensions in Rust

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.

Works with OCaml versions 4.06.0 and up

Documentation

https://docs.rs/ocaml

Examples:

use ocaml::*;

caml!(build_tuple(i) {
    let i = i.val_i32();
    Tuple::from(&[i + 1, i + 2, i + 3])
});

caml!(average(arr) {
    let arr = Array::from(arr);
    let len = arr.len();
    let sum = 0f64;

    for i in 0..len {
        sum += arr.get_double_unchecked(i);
    }

    Value::f64(sum / len as f64)
})

This will take care of all the OCaml garbage collector related bookkeeping (CAMLparam, CAMLlocal and CAMLreturn).

In OCaml the stubs for these functions looks like this:

external build_tuple: int -> int * int * int = "build_tuple"
external average: float array -> float = "average"

For more examples see ./example or ocaml-vec.

caml! macro

The old style caml! macro has been replaced with a much simpler new format.

Instead of:

caml!(function_name, |a, b, c|, <local> {
    ...
} -> local);

you can now write:

caml!(function_name(a, b, c) {
    caml_local!(local);
    ...
    return local;
});

However, when using the type wrappers provided by ocaml-rs (Array, List, Tuple, Str, Array1, ...), caml_local! is already called internally. This means that the following is valid without having to declare a local value for the result:

caml!(example(a, b, c){
    List::from(&[a, b, c])
});