• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 typedef char Buffer[12];
88 
89 size_t c_return_primitive();
90 Shared c_return_shared();
91 ::A::AShared c_return_ns_shared();
92 ::A::B::ABShared c_return_nested_ns_shared();
93 rust::Box<R> c_return_box();
94 std::unique_ptr<C> c_return_unique_ptr();
95 std::shared_ptr<C> c_return_shared_ptr();
96 std::unique_ptr<::H::H> c_return_ns_unique_ptr();
97 const size_t &c_return_ref(const Shared &shared);
98 const size_t &c_return_ns_ref(const ::A::AShared &shared);
99 const size_t &c_return_nested_ns_ref(const ::A::B::ABShared &shared);
100 size_t &c_return_mut(Shared &shared);
101 rust::Str c_return_str(const Shared &shared);
102 rust::Slice<const char> c_return_slice_char(const Shared &shared);
103 rust::Slice<uint8_t> c_return_mutsliceu8(rust::Slice<uint8_t> slice);
104 rust::String c_return_rust_string();
105 rust::String c_return_rust_string_lossy();
106 std::unique_ptr<std::string> c_return_unique_ptr_string();
107 std::unique_ptr<std::vector<uint8_t>> c_return_unique_ptr_vector_u8();
108 std::unique_ptr<std::vector<double>> c_return_unique_ptr_vector_f64();
109 std::unique_ptr<std::vector<std::string>> c_return_unique_ptr_vector_string();
110 std::unique_ptr<std::vector<Shared>> c_return_unique_ptr_vector_shared();
111 std::unique_ptr<std::vector<C>> c_return_unique_ptr_vector_opaque();
112 const std::vector<uint8_t> &c_return_ref_vector(const C &c);
113 std::vector<uint8_t> &c_return_mut_vector(C &c);
114 rust::Vec<uint8_t> c_return_rust_vec_u8();
115 const rust::Vec<uint8_t> &c_return_ref_rust_vec(const C &c);
116 rust::Vec<uint8_t> &c_return_mut_rust_vec(C &c);
117 rust::Vec<rust::String> c_return_rust_vec_string();
118 rust::Vec<bool> c_return_rust_vec_bool();
119 size_t c_return_identity(size_t n);
120 size_t c_return_sum(size_t n1, size_t n2);
121 Enum c_return_enum(uint16_t n);
122 ::A::AEnum c_return_ns_enum(uint16_t n);
123 ::A::B::ABEnum c_return_nested_ns_enum(uint16_t n);
124 std::unique_ptr<Borrow> c_return_borrow(const std::string &s);
125 const C *c_return_const_ptr(size_t n);
126 C *c_return_mut_ptr(size_t n);
127 
128 void c_take_primitive(size_t n);
129 void c_take_shared(Shared shared);
130 void c_take_ns_shared(::A::AShared shared);
131 void c_take_nested_ns_shared(::A::B::ABShared shared);
132 void c_take_box(rust::Box<R> r);
133 void c_take_unique_ptr(std::unique_ptr<C> c);
134 void c_take_ref_r(const R &r);
135 void c_take_ref_c(const C &c);
136 void c_take_ref_ns_c(const ::H::H &h);
137 void c_take_str(rust::Str s);
138 void c_take_slice_char(rust::Slice<const char> s);
139 void c_take_slice_shared(rust::Slice<const Shared> s);
140 void c_take_slice_shared_sort(rust::Slice<Shared> s);
141 void c_take_slice_r(rust::Slice<const R> s);
142 void c_take_slice_r_sort(rust::Slice<R> s);
143 void c_take_rust_string(rust::String s);
144 void c_take_unique_ptr_string(std::unique_ptr<std::string> s);
145 void c_take_unique_ptr_vector_u8(std::unique_ptr<std::vector<uint8_t>> v);
146 void c_take_unique_ptr_vector_f64(std::unique_ptr<std::vector<double>> v);
147 void c_take_unique_ptr_vector_string(
148     std::unique_ptr<std::vector<std::string>> v);
149 void c_take_unique_ptr_vector_shared(std::unique_ptr<std::vector<Shared>> v);
150 void c_take_ref_vector(const std::vector<uint8_t> &v);
151 void c_take_rust_vec(rust::Vec<uint8_t> v);
152 void c_take_rust_vec_index(rust::Vec<uint8_t> v);
153 void c_take_rust_vec_shared(rust::Vec<Shared> v);
154 void c_take_rust_vec_ns_shared(rust::Vec<::A::AShared> v);
155 void c_take_rust_vec_nested_ns_shared(rust::Vec<::A::B::ABShared> v);
156 void c_take_rust_vec_string(rust::Vec<rust::String> v);
157 void c_take_rust_vec_shared_index(rust::Vec<Shared> v);
158 void c_take_rust_vec_shared_push(rust::Vec<Shared> v);
159 void c_take_rust_vec_shared_truncate(rust::Vec<Shared> v);
160 void c_take_rust_vec_shared_clear(rust::Vec<Shared> v);
161 void c_take_rust_vec_shared_forward_iterator(rust::Vec<Shared> v);
162 void c_take_rust_vec_shared_sort(rust::Vec<Shared> v);
163 void c_take_ref_rust_vec(const rust::Vec<uint8_t> &v);
164 void c_take_ref_rust_vec_string(const rust::Vec<rust::String> &v);
165 void c_take_ref_rust_vec_index(const rust::Vec<uint8_t> &v);
166 void c_take_ref_rust_vec_copy(const rust::Vec<uint8_t> &v);
167 const SharedString &c_take_ref_shared_string(const SharedString &s);
168 void c_take_callback(rust::Fn<size_t(rust::String)> callback);
169 void c_take_callback_ref(rust::Fn<void(const rust::String &)> callback);
170 void c_take_callback_mut(rust::Fn<void(rust::String &)> callback);
171 void c_take_enum(Enum e);
172 void c_take_ns_enum(::A::AEnum e);
173 void c_take_nested_ns_enum(::A::B::ABEnum e);
174 size_t c_take_const_ptr(const C *c);
175 size_t c_take_mut_ptr(C *c);
176 
177 void c_try_return_void();
178 size_t c_try_return_primitive();
179 size_t c_fail_return_primitive();
180 rust::Box<R> c_try_return_box();
181 const rust::String &c_try_return_ref(const rust::String &);
182 rust::Str c_try_return_str(rust::Str);
183 rust::Slice<const uint8_t> c_try_return_sliceu8(rust::Slice<const uint8_t>);
184 rust::Slice<uint8_t> c_try_return_mutsliceu8(rust::Slice<uint8_t>);
185 rust::String c_try_return_rust_string();
186 std::unique_ptr<std::string> c_try_return_unique_ptr_string();
187 rust::Vec<uint8_t> c_try_return_rust_vec();
188 rust::Vec<rust::String> c_try_return_rust_vec_string();
189 const rust::Vec<uint8_t> &c_try_return_ref_rust_vec(const C &c);
190 
191 size_t c_get_use_count(const std::weak_ptr<C> &weak) noexcept;
192 
193 void c_take_trivial_ptr(std::unique_ptr<D> d);
194 void c_take_trivial_ref(const D &d);
195 void c_take_trivial_mut_ref(D &d);
196 void c_take_trivial_pin_ref(const D &d);
197 void c_take_trivial_pin_mut_ref(D &d);
198 void c_take_trivial(D d);
199 
200 void c_take_trivial_ns_ptr(std::unique_ptr<::G::G> g);
201 void c_take_trivial_ns_ref(const ::G::G &g);
202 void c_take_trivial_ns(::G::G g);
203 void c_take_opaque_ptr(std::unique_ptr<E> e);
204 void c_take_opaque_ns_ptr(std::unique_ptr<::F::F> f);
205 void c_take_opaque_ref(const E &e);
206 void c_take_opaque_ns_ref(const ::F::F &f);
207 std::unique_ptr<D> c_return_trivial_ptr();
208 D c_return_trivial();
209 std::unique_ptr<::G::G> c_return_trivial_ns_ptr();
210 ::G::G c_return_trivial_ns();
211 std::unique_ptr<E> c_return_opaque_ptr();
212 E &c_return_opaque_mut_pin(E &e);
213 std::unique_ptr<::F::F> c_return_ns_opaque_ptr();
214 
215 rust::String cOverloadedFunction(int32_t x);
216 rust::String cOverloadedFunction(rust::Str x);
217 
218 } // namespace tests
219 
220 namespace other {
221 void ns_c_take_trivial(::tests::D d);
222 ::tests::D ns_c_return_trivial();
223 void ns_c_take_ns_shared(::A::AShared shared);
224 } // namespace other
225 
226 namespace I {
227 class I {
228 private:
229   uint32_t a;
230 
231 public:
I()232   I() : a(1000) {}
233   uint32_t get() const;
234 };
235 
236 std::unique_ptr<I> ns_c_return_unique_ptr_ns();
237 } // namespace I
238