[][src]Macro ocaml_interop::ocaml

macro_rules! ocaml {
    () => { ... };
    ($vis:vis fn $name:ident(
        $arg:ident: $typ:ty $(,)?
    ) $(-> $rtyp:ty)?; $($t:tt)*) => { ... };
    ($vis:vis fn $name:ident(
        $arg1:ident: $typ1:ty,
        $arg2:ident: $typ2:ty $(,)?
    ) $(-> $rtyp:ty)?; $($t:tt)*) => { ... };
    ($vis:vis fn $name:ident(
        $arg1:ident: $typ1:ty,
        $arg2:ident: $typ2:ty,
        $arg3:ident: $typ3:ty $(,)?
    ) $(-> $rtyp:ty)?; $($t:tt)*) => { ... };
    ($vis:vis fn $name:ident(
        $($arg:ident: $typ:ty),+ $(,)?
    ) $(-> $rtyp:ty)?; $($t:tt)*) => { ... };
}

Declares OCaml functions and allocators.

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.

These functions must be invoked with the ocaml_call! macro.

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;
}