derive-ocaml

Crates.ioderive-ocaml
lib.rsderive-ocaml
version0.1.3
sourcesrc
created_at2018-07-21 09:56:27.399488
updated_at2021-02-12 13:44:04.28125
descriptionCustom derive and procedural macros for easy FFI with ocaml on top of the ocaml crate
homepagehttps://github.com/ahrefs/rust-ocaml-derive
repositoryhttps://github.com/ahrefs/rust-ocaml-derive
max_upload_size
id75321
size16,814
Publish Ecosystem (github:tower-rs:publish-ecosystem)

documentation

README

derive-ocaml - Custom derive and procedural macros for easier ocaml <-> rust FFI

WARNING this crate is very experimental

derive-ocaml is based on top of ocaml-rs and adds a custom derive macro for FromValue and ToValue. The macro supports structs, enums, and unboxed float records.

On top of that it implements a nightly only procedural macro ocaml-ffi to ease the boilerplate of writing stubs functions.

#[derive(Debug, Default, ToValue, FromValue)]
#[ocaml(floats_array)]
pub struct Vec3 {
    x: f32,
    y: f32,
    z: f32,
}

#[ocaml_ffi]
pub fn rust_add_vecs(l: Vec3, r: Vec3) -> Vec3 {
    l + r
}

see src/example/src/lib.rs and src/example/src/stubs.ml for example

Commit count: 27

cargo fmt