ocamlgen_test_stubs/
lib.rs

1#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
2pub struct SingleTuple(String);
3
4#[ocaml_gen::func]
5#[ocaml::func]
6pub fn new() -> SingleTuple {
7    SingleTuple(String::from("Hello"))
8}
9
10#[ocaml_gen::func]
11#[ocaml::func]
12pub fn print(s: SingleTuple) {
13    println!("{}", s.0);
14}
15
16#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::CustomType)]
17pub struct Car {
18    name: String,
19    doors: usize,
20}
21
22#[ocaml_gen::func]
23#[ocaml::func]
24pub fn create_toyota() -> Car {
25    Car {
26        name: String::from("Toyota"),
27        doors: 4,
28    }
29}
30
31#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
32pub struct Package<T> {
33    gift: T,
34}
35
36#[ocaml_gen::func]
37#[ocaml::func]
38pub fn pack_present() -> Package<String> {
39    Package {
40        gift: "hello".to_string(),
41    }
42}
43
44#[ocaml_gen::func]
45#[ocaml::func]
46pub fn fn_one_parameter(v1: Car) -> Car {
47    v1
48}
49
50#[ocaml_gen::func]
51#[ocaml::func]
52pub fn fn_two_parameters(v1: Car, _v2: usize) -> Car {
53    v1
54}
55
56#[ocaml_gen::func]
57#[ocaml::func]
58pub fn fn_three_parameters(v1: Car, _v2: usize, _v3: usize) -> Car {
59    v1
60}
61
62#[ocaml_gen::func]
63#[ocaml::func]
64pub fn fn_four_parameters(v1: Car, _v2: usize, _v3: usize, _v4: usize) -> Car {
65    v1
66}
67
68#[ocaml_gen::func]
69#[ocaml::func]
70pub fn fn_five_parameters(v1: Car, _v2: usize, _v3: usize, _v4: usize, _v5: usize) -> Car {
71    v1
72}
73
74#[ocaml_gen::func]
75#[ocaml::func]
76pub fn fn_six_parameters(
77    v1: Car,
78    _v2: usize,
79    _v3: usize,
80    _v4: usize,
81    _v5: usize,
82    _v6: usize,
83) -> Car {
84    v1
85}
86// Test OCamlDesc is implemented for i32
87#[ocaml_gen::func]
88#[ocaml::func]
89pub fn test_add_i32(s1: i32, s2: i32) -> i32 {
90    s1 + s2
91}
92
93#[ocaml_gen::func]
94#[ocaml::func]
95pub fn test_add_usize(s1: usize, s2: usize) -> usize {
96    s1 + s2
97}
98
99#[ocaml_gen::func]
100#[ocaml::func]
101pub fn test_bytes_get(s1: &[u8], i: usize) -> u8 {
102    s1[i]
103}
104
105#[ocaml_gen::func]
106#[ocaml::func]
107pub fn test_get_ascii_code(ascii: u8) -> i32 {
108    ascii as i32
109}