1 #pragma once
2 #include "rust/cxx.h"
3 #include <memory>
4 #include <string>
5 
6 namespace A {
7 struct AShared;
8 enum class AEnum : uint16_t;
9 namespace B {
10 struct ABShared;
11 enum class ABEnum : uint16_t;
12 } // namespace B
13 } // namespace A
14 
15 namespace F {
16 struct F {
17   uint64_t f;
18   std::string f_str;
19 };
20 } // namespace F
21 
22 namespace G {
23 struct G {
24   uint64_t g;
25 };
26 } // namespace G
27 
28 namespace H {
29 class H {
30 public:
31   std::string h;
32 };
33 } // namespace H
34 
35 namespace tests {
36 
37 struct R;
38 struct Shared;
39 struct SharedString;
40 enum class Enum : uint16_t;
41 
42 class C {
43 public:
44   C(size_t n);
45   size_t get() const;
46   size_t set(size_t n);
47   size_t get2() const;
48   const size_t &getRef() const;
49   size_t &getMut();
50   size_t set_succeed(size_t n);
51   size_t get_fail();
52   const std::vector<uint8_t> &get_v() const;
53   std::vector<uint8_t> &get_v();
54   rust::String cOverloadedMethod(int32_t x) const;
55   rust::String cOverloadedMethod(rust::Str x) const;
56 
57 private:
58   size_t n;
59   std::vector<uint8_t> v;
60 };
61 
62 struct D {
63   uint64_t d;
64   void c_take_trivial_ref_method() const;
65   void c_take_trivial_mut_ref_method();
66 };
67 
68 struct E {
69   uint64_t e;
70   std::string e_str;
71   void c_take_opaque_ref_method() const;
72   void c_take_opaque_mut_ref_method();
73 };
74 
75 enum COwnedEnum {
76   CVAL1,
77   CVAL2,
78 };
79 
80 struct Borrow {
81   Borrow(const std::string &s);
82   void const_member() const;
83   void nonconst_member();
84   const std::string &s;
85 };
86 
87 size_t c_return_primitive();
88 Shared c_return_shared();
89 ::A::AShared c_return_ns_shared();
90 ::A::B::ABShared c_return_nested_ns_shared();
91 rust::Box<R> c_return_box();
92 std::unique_ptr<C> c_return_unique_ptr();
93 std::shared_ptr<C> c_return_shared_ptr();
94 std::unique_ptr<::H::H> c_return_ns_unique_ptr();
95 const size_t &c_return_ref(const Shared &shared);
96 const size_t &c_return_ns_ref(const ::A::AShared &shared);
97 const size_t &c_return_nested_ns_ref(const ::A::B::ABShared &shared);
98 size_t &c_return_mut(Shared &shared);
99 rust::Str c_return_str(const Shared &shared);
100 rust::Slice<const char> c_return_slice_char(const Shared &shared);
101 rust::Slice<uint8_t> c_return_mutsliceu8(rust::Slice<uint8_t> slice);
102 rust::String c_return_rust_string();
103 std::unique_ptr<std::string> c_return_unique_ptr_string();
104 std::unique_ptr<std::vector<uint8_t>> c_return_unique_ptr_vector_u8();
105 std::unique_ptr<std::vector<double>> c_return_unique_ptr_vector_f64();
106 std::unique_ptr<std::vector<std::string>> c_return_unique_ptr_vector_string();
107 std::unique_ptr<std::vector<Shared>> c_return_unique_ptr_vector_shared();
108 std::unique_ptr<std::vector<C>> c_return_unique_ptr_vector_opaque();
109 const std::vector<uint8_t> &c_return_ref_vector(const C &c);
110 std::vector<uint8_t> &c_return_mut_vector(C &c);
111 rust::Vec<uint8_t> c_return_rust_vec();
112 const rust::Vec<uint8_t> &c_return_ref_rust_vec(const C &c);
113 rust::Vec<uint8_t> &c_return_mut_rust_vec(C &c);
114 rust::Vec<rust::String> c_return_rust_vec_string();
115 size_t c_return_identity(size_t n);
116 size_t c_return_sum(size_t n1, size_t n2);
117 Enum c_return_enum(uint16_t n);
118 ::A::AEnum c_return_ns_enum(uint16_t n);
119 ::A::B::ABEnum c_return_nested_ns_enum(uint16_t n);
120 std::unique_ptr<Borrow> c_return_borrow(const std::string &s);
121 const C *c_return_const_ptr(size_t n);
122 C *c_return_mut_ptr(size_t n);
123 
124 void c_take_primitive(size_t n);
125 void c_take_shared(Shared shared);
126 void c_take_ns_shared(::A::AShared shared);
127 void c_take_nested_ns_shared(::A::B::ABShared shared);
128 void c_take_box(rust::Box<R> r);
129 void c_take_unique_ptr(std::unique_ptr<C> c);
130 void c_take_ref_r(const R &r);
131 void c_take_ref_c(const C &c);
132 void c_take_ref_ns_c(const ::H::H &h);
133 void c_take_str(rust::Str s);
134 void c_take_slice_char(rust::Slice<const char> s);
135 void c_take_slice_shared(rust::Slice<const Shared> s);
136 void c_take_slice_shared_sort(rust::Slice<Shared> s);
137 void c_take_slice_r(rust::Slice<const R> s);
138 void c_take_slice_r_sort(rust::Slice<R> s);
139 void c_take_rust_string(rust::String s);
140 void c_take_unique_ptr_string(std::unique_ptr<std::string> s);
141 void c_take_unique_ptr_vector_u8(std::unique_ptr<std::vector<uint8_t>> v);
142 void c_take_unique_ptr_vector_f64(std::unique_ptr<std::vector<double>> v);
143 void c_take_unique_ptr_vector_string(
144     std::unique_ptr<std::vector<std::string>> v);
145 void c_take_unique_ptr_vector_shared(std::unique_ptr<std::vector<Shared>> v);
146 void c_take_ref_vector(const std::vector<uint8_t> &v);
147 void c_take_rust_vec(rust::Vec<uint8_t> v);
148 void c_take_rust_vec_index(rust::Vec<uint8_t> v);
149 void c_take_rust_vec_shared(rust::Vec<Shared> v);
150 void c_take_rust_vec_ns_shared(rust::Vec<::A::AShared> v);
151 void c_take_rust_vec_nested_ns_shared(rust::Vec<::A::B::ABShared> v);
152 void c_take_rust_vec_string(rust::Vec<rust::String> v);
153 void c_take_rust_vec_shared_index(rust::Vec<Shared> v);
154 void c_take_rust_vec_shared_push(rust::Vec<Shared> v);
155 void c_take_rust_vec_shared_forward_iterator(rust::Vec<Shared> v);
156 void c_take_rust_vec_shared_sort(rust::Vec<Shared> v);
157 void c_take_ref_rust_vec(const rust::Vec<uint8_t> &v);
158 void c_take_ref_rust_vec_string(const rust::Vec<rust::String> &v);
159 void c_take_ref_rust_vec_index(const rust::Vec<uint8_t> &v);
160 void c_take_ref_rust_vec_copy(const rust::Vec<uint8_t> &v);
161 const SharedString &c_take_ref_shared_string(const SharedString &s);
162 void c_take_callback(rust::Fn<size_t(rust::String)> callback);
163 void c_take_enum(Enum e);
164 void c_take_ns_enum(::A::AEnum e);
165 void c_take_nested_ns_enum(::A::B::ABEnum e);
166 size_t c_take_const_ptr(const C *c);
167 size_t c_take_mut_ptr(C *c);
168 
169 void c_try_return_void();
170 size_t c_try_return_primitive();
171 size_t c_fail_return_primitive();
172 rust::Box<R> c_try_return_box();
173 const rust::String &c_try_return_ref(const rust::String &);
174 rust::Str c_try_return_str(rust::Str);
175 rust::Slice<const uint8_t> c_try_return_sliceu8(rust::Slice<const uint8_t>);
176 rust::Slice<uint8_t> c_try_return_mutsliceu8(rust::Slice<uint8_t>);
177 rust::String c_try_return_rust_string();
178 std::unique_ptr<std::string> c_try_return_unique_ptr_string();
179 rust::Vec<uint8_t> c_try_return_rust_vec();
180 rust::Vec<rust::String> c_try_return_rust_vec_string();
181 const rust::Vec<uint8_t> &c_try_return_ref_rust_vec(const C &c);
182 
183 size_t c_get_use_count(const std::weak_ptr<C> &weak) noexcept;
184 
185 void c_take_trivial_ptr(std::unique_ptr<D> d);
186 void c_take_trivial_ref(const D &d);
187 void c_take_trivial_mut_ref(D &d);
188 void c_take_trivial_pin_ref(const D &d);
189 void c_take_trivial_pin_mut_ref(D &d);
190 void c_take_trivial(D d);
191 
192 void c_take_trivial_ns_ptr(std::unique_ptr<::G::G> g);
193 void c_take_trivial_ns_ref(const ::G::G &g);
194 void c_take_trivial_ns(::G::G g);
195 void c_take_opaque_ptr(std::unique_ptr<E> e);
196 void c_take_opaque_ns_ptr(std::unique_ptr<::F::F> f);
197 void c_take_opaque_ref(const E &e);
198 void c_take_opaque_ns_ref(const ::F::F &f);
199 std::unique_ptr<D> c_return_trivial_ptr();
200 D c_return_trivial();
201 std::unique_ptr<::G::G> c_return_trivial_ns_ptr();
202 ::G::G c_return_trivial_ns();
203 std::unique_ptr<E> c_return_opaque_ptr();
204 E &c_return_opaque_mut_pin(E &e);
205 std::unique_ptr<::F::F> c_return_ns_opaque_ptr();
206 
207 rust::String cOverloadedFunction(int32_t x);
208 rust::String cOverloadedFunction(rust::Str x);
209 
210 } // namespace tests
211 
212 namespace other {
213 void ns_c_take_trivial(::tests::D d);
214 ::tests::D ns_c_return_trivial();
215 void ns_c_take_ns_shared(::A::AShared shared);
216 } // namespace other
217 
218 namespace I {
219 class I {
220 private:
221   uint32_t a;
222 
223 public:
I()224   I() : a(1000) {}
225   uint32_t get() const;
226 };
227 
228 std::unique_ptr<I> ns_c_return_unique_ptr_ns();
229 } // namespace I
230