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