[−][src]Macro ocaml_interop::ocaml
Declares OCaml functions.
ocaml! { pub fn ocaml_name(arg1: Typ1, ...) -> Ret_typ; ... }
declares a function that has been
defined in OCaml code and registered with Callback.register "ocaml_name" the_function
.
Visibility and return value type can be omitted. The return type defaults to unit when omitted.
When invoking one of these functions, the first argument must be a &mut OCamlRuntime
,
and the remaining arguments OCamlRef<ArgT>
.
The return value is an OCaml<RetType>
.
Calls that raise an OCaml exception will panic!
.
Examples
ocaml! { // Declares `print_endline`, with a single `String` (`OCaml<String>` when invoked) // argument and unit return type (default when omitted). pub fn print_endline(s: String); // Declares `bytes_concat`, with two arguments, an OCaml `bytes` separator, // and an OCaml list of segments to concatenate. Return value is an OCaml `bytes` // value. fn bytes_concat(sep: OCamlBytes, segments: OCamlList<OCamlBytes>) -> OCamlBytes; }