react-native-nitro-ark 0.0.77-rc.7 → 0.0.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/Ark.xcframework/Info.plist +0 -47
- package/Ark.xcframework/ios-arm64/libbark_cpp.a +0 -0
- package/Ark.xcframework/ios-arm64-simulator/libbark_cpp.a +0 -0
- package/ArkCxxBridge.xcframework/Info.plist +0 -47
- package/ArkCxxBridge.xcframework/ios-arm64/Headers/ark_cxx.h +0 -1241
- package/ArkCxxBridge.xcframework/ios-arm64/Headers/cxx.h +0 -1149
- package/ArkCxxBridge.xcframework/ios-arm64/libcxxbridge1.a +0 -0
- package/ArkCxxBridge.xcframework/ios-arm64-simulator/Headers/ark_cxx.h +0 -1241
- package/ArkCxxBridge.xcframework/ios-arm64-simulator/Headers/cxx.h +0 -1149
- package/ArkCxxBridge.xcframework/ios-arm64-simulator/libcxxbridge1.a +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libbark_cpp.a +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libbark_cpp.a +0 -0
- package/android/src/main/jniLibs/x86_64/libbark_cpp.a +0 -0
|
@@ -1,1149 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
#include <algorithm>
|
|
3
|
-
#include <array>
|
|
4
|
-
#include <cassert>
|
|
5
|
-
#include <cstddef>
|
|
6
|
-
#include <cstdint>
|
|
7
|
-
#include <exception>
|
|
8
|
-
#include <initializer_list>
|
|
9
|
-
#include <iosfwd>
|
|
10
|
-
#include <iterator>
|
|
11
|
-
#include <new>
|
|
12
|
-
#include <stdexcept>
|
|
13
|
-
#include <string>
|
|
14
|
-
#include <type_traits>
|
|
15
|
-
#include <utility>
|
|
16
|
-
#include <vector>
|
|
17
|
-
#if defined(_WIN32)
|
|
18
|
-
#include <basetsd.h>
|
|
19
|
-
#else
|
|
20
|
-
#include <sys/types.h>
|
|
21
|
-
#endif
|
|
22
|
-
|
|
23
|
-
#if __cplusplus >= 201703L
|
|
24
|
-
#include <string_view>
|
|
25
|
-
#endif
|
|
26
|
-
|
|
27
|
-
#if __cplusplus >= 202002L
|
|
28
|
-
#include <ranges>
|
|
29
|
-
#endif
|
|
30
|
-
|
|
31
|
-
namespace rust {
|
|
32
|
-
inline namespace cxxbridge1 {
|
|
33
|
-
|
|
34
|
-
struct unsafe_bitcopy_t;
|
|
35
|
-
|
|
36
|
-
namespace {
|
|
37
|
-
template <typename T>
|
|
38
|
-
class impl;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
#ifndef CXXBRIDGE1_RUST_STRING
|
|
42
|
-
#define CXXBRIDGE1_RUST_STRING
|
|
43
|
-
// https://cxx.rs/binding/string.html
|
|
44
|
-
class String final {
|
|
45
|
-
public:
|
|
46
|
-
String() noexcept;
|
|
47
|
-
String(const String &) noexcept;
|
|
48
|
-
String(String &&) noexcept;
|
|
49
|
-
~String() noexcept;
|
|
50
|
-
|
|
51
|
-
String(const std::string &);
|
|
52
|
-
String(const char *);
|
|
53
|
-
String(const char *, std::size_t);
|
|
54
|
-
String(const char16_t *);
|
|
55
|
-
String(const char16_t *, std::size_t);
|
|
56
|
-
#ifdef __cpp_char8_t
|
|
57
|
-
String(const char8_t *s);
|
|
58
|
-
String(const char8_t *s, std::size_t len);
|
|
59
|
-
#endif
|
|
60
|
-
|
|
61
|
-
// Replace invalid Unicode data with the replacement character (U+FFFD).
|
|
62
|
-
static String lossy(const std::string &) noexcept;
|
|
63
|
-
static String lossy(const char *) noexcept;
|
|
64
|
-
static String lossy(const char *, std::size_t) noexcept;
|
|
65
|
-
static String lossy(const char16_t *) noexcept;
|
|
66
|
-
static String lossy(const char16_t *, std::size_t) noexcept;
|
|
67
|
-
|
|
68
|
-
String &operator=(const String &) & noexcept;
|
|
69
|
-
String &operator=(String &&) & noexcept;
|
|
70
|
-
|
|
71
|
-
explicit operator std::string() const;
|
|
72
|
-
|
|
73
|
-
// Note: no null terminator.
|
|
74
|
-
const char *data() const noexcept;
|
|
75
|
-
std::size_t size() const noexcept;
|
|
76
|
-
std::size_t length() const noexcept;
|
|
77
|
-
bool empty() const noexcept;
|
|
78
|
-
|
|
79
|
-
const char *c_str() noexcept;
|
|
80
|
-
|
|
81
|
-
std::size_t capacity() const noexcept;
|
|
82
|
-
void reserve(size_t new_cap) noexcept;
|
|
83
|
-
|
|
84
|
-
using iterator = char *;
|
|
85
|
-
iterator begin() noexcept;
|
|
86
|
-
iterator end() noexcept;
|
|
87
|
-
|
|
88
|
-
using const_iterator = const char *;
|
|
89
|
-
const_iterator begin() const noexcept;
|
|
90
|
-
const_iterator end() const noexcept;
|
|
91
|
-
const_iterator cbegin() const noexcept;
|
|
92
|
-
const_iterator cend() const noexcept;
|
|
93
|
-
|
|
94
|
-
bool operator==(const String &) const noexcept;
|
|
95
|
-
bool operator!=(const String &) const noexcept;
|
|
96
|
-
bool operator<(const String &) const noexcept;
|
|
97
|
-
bool operator<=(const String &) const noexcept;
|
|
98
|
-
bool operator>(const String &) const noexcept;
|
|
99
|
-
bool operator>=(const String &) const noexcept;
|
|
100
|
-
|
|
101
|
-
void swap(String &) noexcept;
|
|
102
|
-
|
|
103
|
-
// Internal API only intended for the cxxbridge code generator.
|
|
104
|
-
String(unsafe_bitcopy_t, const String &) noexcept;
|
|
105
|
-
|
|
106
|
-
private:
|
|
107
|
-
struct lossy_t;
|
|
108
|
-
String(lossy_t, const char *, std::size_t) noexcept;
|
|
109
|
-
String(lossy_t, const char16_t *, std::size_t) noexcept;
|
|
110
|
-
friend void swap(String &lhs, String &rhs) noexcept { lhs.swap(rhs); }
|
|
111
|
-
|
|
112
|
-
// Size and alignment statically verified by rust_string.rs.
|
|
113
|
-
std::array<std::uintptr_t, 3> repr;
|
|
114
|
-
};
|
|
115
|
-
#endif // CXXBRIDGE1_RUST_STRING
|
|
116
|
-
|
|
117
|
-
#ifndef CXXBRIDGE1_RUST_STR
|
|
118
|
-
#define CXXBRIDGE1_RUST_STR
|
|
119
|
-
// https://cxx.rs/binding/str.html
|
|
120
|
-
class Str final {
|
|
121
|
-
public:
|
|
122
|
-
Str() noexcept;
|
|
123
|
-
Str(const String &) noexcept;
|
|
124
|
-
Str(const std::string &);
|
|
125
|
-
Str(const char *);
|
|
126
|
-
Str(const char *, std::size_t);
|
|
127
|
-
|
|
128
|
-
Str &operator=(const Str &) & noexcept = default;
|
|
129
|
-
|
|
130
|
-
explicit operator std::string() const;
|
|
131
|
-
#if __cplusplus >= 201703L
|
|
132
|
-
explicit operator std::string_view() const;
|
|
133
|
-
#endif
|
|
134
|
-
|
|
135
|
-
// Note: no null terminator.
|
|
136
|
-
const char *data() const noexcept;
|
|
137
|
-
std::size_t size() const noexcept;
|
|
138
|
-
std::size_t length() const noexcept;
|
|
139
|
-
bool empty() const noexcept;
|
|
140
|
-
|
|
141
|
-
// Important in order for System V ABI to pass in registers.
|
|
142
|
-
Str(const Str &) noexcept = default;
|
|
143
|
-
~Str() noexcept = default;
|
|
144
|
-
|
|
145
|
-
using iterator = const char *;
|
|
146
|
-
using const_iterator = const char *;
|
|
147
|
-
const_iterator begin() const noexcept;
|
|
148
|
-
const_iterator end() const noexcept;
|
|
149
|
-
const_iterator cbegin() const noexcept;
|
|
150
|
-
const_iterator cend() const noexcept;
|
|
151
|
-
|
|
152
|
-
bool operator==(const Str &) const noexcept;
|
|
153
|
-
bool operator!=(const Str &) const noexcept;
|
|
154
|
-
bool operator<(const Str &) const noexcept;
|
|
155
|
-
bool operator<=(const Str &) const noexcept;
|
|
156
|
-
bool operator>(const Str &) const noexcept;
|
|
157
|
-
bool operator>=(const Str &) const noexcept;
|
|
158
|
-
|
|
159
|
-
void swap(Str &) noexcept;
|
|
160
|
-
|
|
161
|
-
private:
|
|
162
|
-
class uninit;
|
|
163
|
-
Str(uninit) noexcept;
|
|
164
|
-
friend impl<Str>;
|
|
165
|
-
|
|
166
|
-
std::array<std::uintptr_t, 2> repr;
|
|
167
|
-
};
|
|
168
|
-
#endif // CXXBRIDGE1_RUST_STR
|
|
169
|
-
|
|
170
|
-
#ifndef CXXBRIDGE1_RUST_SLICE
|
|
171
|
-
namespace detail {
|
|
172
|
-
template <bool>
|
|
173
|
-
struct copy_assignable_if {};
|
|
174
|
-
|
|
175
|
-
template <>
|
|
176
|
-
struct copy_assignable_if<false> {
|
|
177
|
-
copy_assignable_if() noexcept = default;
|
|
178
|
-
copy_assignable_if(const copy_assignable_if &) noexcept = default;
|
|
179
|
-
copy_assignable_if &operator=(const copy_assignable_if &) & noexcept = delete;
|
|
180
|
-
copy_assignable_if &operator=(copy_assignable_if &&) & noexcept = default;
|
|
181
|
-
};
|
|
182
|
-
} // namespace detail
|
|
183
|
-
|
|
184
|
-
// https://cxx.rs/binding/slice.html
|
|
185
|
-
template <typename T>
|
|
186
|
-
class Slice final
|
|
187
|
-
: private detail::copy_assignable_if<std::is_const<T>::value> {
|
|
188
|
-
public:
|
|
189
|
-
using value_type = T;
|
|
190
|
-
|
|
191
|
-
Slice() noexcept;
|
|
192
|
-
Slice(T *, std::size_t count) noexcept;
|
|
193
|
-
|
|
194
|
-
template <typename C>
|
|
195
|
-
explicit Slice(C &c) : Slice(c.data(), c.size()) {}
|
|
196
|
-
|
|
197
|
-
Slice &operator=(const Slice<T> &) & noexcept = default;
|
|
198
|
-
Slice &operator=(Slice<T> &&) & noexcept = default;
|
|
199
|
-
|
|
200
|
-
T *data() const noexcept;
|
|
201
|
-
std::size_t size() const noexcept;
|
|
202
|
-
std::size_t length() const noexcept;
|
|
203
|
-
bool empty() const noexcept;
|
|
204
|
-
|
|
205
|
-
T &operator[](std::size_t n) const noexcept;
|
|
206
|
-
T &at(std::size_t n) const;
|
|
207
|
-
T &front() const noexcept;
|
|
208
|
-
T &back() const noexcept;
|
|
209
|
-
|
|
210
|
-
// Important in order for System V ABI to pass in registers.
|
|
211
|
-
Slice(const Slice<T> &) noexcept = default;
|
|
212
|
-
~Slice() noexcept = default;
|
|
213
|
-
|
|
214
|
-
class iterator;
|
|
215
|
-
iterator begin() const noexcept;
|
|
216
|
-
iterator end() const noexcept;
|
|
217
|
-
|
|
218
|
-
void swap(Slice &) noexcept;
|
|
219
|
-
|
|
220
|
-
private:
|
|
221
|
-
class uninit;
|
|
222
|
-
Slice(uninit) noexcept;
|
|
223
|
-
friend impl<Slice>;
|
|
224
|
-
friend void sliceInit(void *, const void *, std::size_t) noexcept;
|
|
225
|
-
friend void *slicePtr(const void *) noexcept;
|
|
226
|
-
friend std::size_t sliceLen(const void *) noexcept;
|
|
227
|
-
|
|
228
|
-
std::array<std::uintptr_t, 2> repr;
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
#ifdef __cpp_deduction_guides
|
|
232
|
-
template <typename C>
|
|
233
|
-
explicit Slice(C &c)
|
|
234
|
-
-> Slice<std::remove_reference_t<decltype(*std::declval<C>().data())>>;
|
|
235
|
-
#endif // __cpp_deduction_guides
|
|
236
|
-
|
|
237
|
-
template <typename T>
|
|
238
|
-
class Slice<T>::iterator final {
|
|
239
|
-
public:
|
|
240
|
-
#if __cplusplus >= 202002L
|
|
241
|
-
using iterator_category = std::contiguous_iterator_tag;
|
|
242
|
-
#else
|
|
243
|
-
using iterator_category = std::random_access_iterator_tag;
|
|
244
|
-
#endif
|
|
245
|
-
using value_type = T;
|
|
246
|
-
using difference_type = std::ptrdiff_t;
|
|
247
|
-
using pointer = typename std::add_pointer<T>::type;
|
|
248
|
-
using reference = typename std::add_lvalue_reference<T>::type;
|
|
249
|
-
|
|
250
|
-
reference operator*() const noexcept;
|
|
251
|
-
pointer operator->() const noexcept;
|
|
252
|
-
reference operator[](difference_type) const noexcept;
|
|
253
|
-
|
|
254
|
-
iterator &operator++() noexcept;
|
|
255
|
-
iterator operator++(int) noexcept;
|
|
256
|
-
iterator &operator--() noexcept;
|
|
257
|
-
iterator operator--(int) noexcept;
|
|
258
|
-
|
|
259
|
-
iterator &operator+=(difference_type) noexcept;
|
|
260
|
-
iterator &operator-=(difference_type) noexcept;
|
|
261
|
-
iterator operator+(difference_type) const noexcept;
|
|
262
|
-
friend inline iterator operator+(difference_type lhs, iterator rhs) noexcept {
|
|
263
|
-
return rhs + lhs;
|
|
264
|
-
}
|
|
265
|
-
iterator operator-(difference_type) const noexcept;
|
|
266
|
-
difference_type operator-(const iterator &) const noexcept;
|
|
267
|
-
|
|
268
|
-
bool operator==(const iterator &) const noexcept;
|
|
269
|
-
bool operator!=(const iterator &) const noexcept;
|
|
270
|
-
bool operator<(const iterator &) const noexcept;
|
|
271
|
-
bool operator<=(const iterator &) const noexcept;
|
|
272
|
-
bool operator>(const iterator &) const noexcept;
|
|
273
|
-
bool operator>=(const iterator &) const noexcept;
|
|
274
|
-
|
|
275
|
-
private:
|
|
276
|
-
friend class Slice;
|
|
277
|
-
void *pos;
|
|
278
|
-
std::size_t stride;
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
#if __cplusplus >= 202002L
|
|
282
|
-
static_assert(std::ranges::contiguous_range<rust::Slice<const uint8_t>>);
|
|
283
|
-
static_assert(std::contiguous_iterator<rust::Slice<const uint8_t>::iterator>);
|
|
284
|
-
#endif
|
|
285
|
-
|
|
286
|
-
#endif // CXXBRIDGE1_RUST_SLICE
|
|
287
|
-
|
|
288
|
-
#ifndef CXXBRIDGE1_RUST_BOX
|
|
289
|
-
// https://cxx.rs/binding/box.html
|
|
290
|
-
template <typename T>
|
|
291
|
-
class Box final {
|
|
292
|
-
public:
|
|
293
|
-
using element_type = T;
|
|
294
|
-
using const_pointer =
|
|
295
|
-
typename std::add_pointer<typename std::add_const<T>::type>::type;
|
|
296
|
-
using pointer = typename std::add_pointer<T>::type;
|
|
297
|
-
|
|
298
|
-
Box() = delete;
|
|
299
|
-
Box(Box &&) noexcept;
|
|
300
|
-
~Box() noexcept;
|
|
301
|
-
|
|
302
|
-
explicit Box(const T &);
|
|
303
|
-
explicit Box(T &&);
|
|
304
|
-
|
|
305
|
-
Box &operator=(Box &&) & noexcept;
|
|
306
|
-
|
|
307
|
-
const T *operator->() const noexcept;
|
|
308
|
-
const T &operator*() const noexcept;
|
|
309
|
-
T *operator->() noexcept;
|
|
310
|
-
T &operator*() noexcept;
|
|
311
|
-
|
|
312
|
-
template <typename... Fields>
|
|
313
|
-
static Box in_place(Fields &&...);
|
|
314
|
-
|
|
315
|
-
void swap(Box &) noexcept;
|
|
316
|
-
|
|
317
|
-
// Important: requires that `raw` came from an into_raw call. Do not pass a
|
|
318
|
-
// pointer from `new` or any other source.
|
|
319
|
-
static Box from_raw(T *) noexcept;
|
|
320
|
-
|
|
321
|
-
T *into_raw() noexcept;
|
|
322
|
-
|
|
323
|
-
/* Deprecated */ using value_type = element_type;
|
|
324
|
-
|
|
325
|
-
private:
|
|
326
|
-
class uninit;
|
|
327
|
-
class allocation;
|
|
328
|
-
Box(uninit) noexcept;
|
|
329
|
-
void drop() noexcept;
|
|
330
|
-
|
|
331
|
-
friend void swap(Box &lhs, Box &rhs) noexcept { lhs.swap(rhs); }
|
|
332
|
-
|
|
333
|
-
T *ptr;
|
|
334
|
-
};
|
|
335
|
-
#endif // CXXBRIDGE1_RUST_BOX
|
|
336
|
-
|
|
337
|
-
#ifndef CXXBRIDGE1_RUST_VEC
|
|
338
|
-
// https://cxx.rs/binding/vec.html
|
|
339
|
-
template <typename T>
|
|
340
|
-
class Vec final {
|
|
341
|
-
public:
|
|
342
|
-
using value_type = T;
|
|
343
|
-
|
|
344
|
-
Vec() noexcept;
|
|
345
|
-
Vec(std::initializer_list<T>);
|
|
346
|
-
Vec(const Vec &);
|
|
347
|
-
Vec(Vec &&) noexcept;
|
|
348
|
-
~Vec() noexcept;
|
|
349
|
-
|
|
350
|
-
Vec &operator=(Vec &&) & noexcept;
|
|
351
|
-
Vec &operator=(const Vec &) &;
|
|
352
|
-
|
|
353
|
-
std::size_t size() const noexcept;
|
|
354
|
-
bool empty() const noexcept;
|
|
355
|
-
const T *data() const noexcept;
|
|
356
|
-
T *data() noexcept;
|
|
357
|
-
std::size_t capacity() const noexcept;
|
|
358
|
-
|
|
359
|
-
const T &operator[](std::size_t n) const noexcept;
|
|
360
|
-
const T &at(std::size_t n) const;
|
|
361
|
-
const T &front() const noexcept;
|
|
362
|
-
const T &back() const noexcept;
|
|
363
|
-
|
|
364
|
-
T &operator[](std::size_t n) noexcept;
|
|
365
|
-
T &at(std::size_t n);
|
|
366
|
-
T &front() noexcept;
|
|
367
|
-
T &back() noexcept;
|
|
368
|
-
|
|
369
|
-
void reserve(std::size_t new_cap);
|
|
370
|
-
void push_back(const T &value);
|
|
371
|
-
void push_back(T &&value);
|
|
372
|
-
template <typename... Args>
|
|
373
|
-
void emplace_back(Args &&...args);
|
|
374
|
-
void truncate(std::size_t len);
|
|
375
|
-
void clear();
|
|
376
|
-
|
|
377
|
-
using iterator = typename Slice<T>::iterator;
|
|
378
|
-
iterator begin() noexcept;
|
|
379
|
-
iterator end() noexcept;
|
|
380
|
-
|
|
381
|
-
using const_iterator = typename Slice<const T>::iterator;
|
|
382
|
-
const_iterator begin() const noexcept;
|
|
383
|
-
const_iterator end() const noexcept;
|
|
384
|
-
const_iterator cbegin() const noexcept;
|
|
385
|
-
const_iterator cend() const noexcept;
|
|
386
|
-
|
|
387
|
-
void swap(Vec &) noexcept;
|
|
388
|
-
|
|
389
|
-
// Internal API only intended for the cxxbridge code generator.
|
|
390
|
-
Vec(unsafe_bitcopy_t, const Vec &) noexcept;
|
|
391
|
-
|
|
392
|
-
private:
|
|
393
|
-
void reserve_total(std::size_t new_cap) noexcept;
|
|
394
|
-
void set_len(std::size_t len) noexcept;
|
|
395
|
-
void drop() noexcept;
|
|
396
|
-
|
|
397
|
-
friend void swap(Vec &lhs, Vec &rhs) noexcept { lhs.swap(rhs); }
|
|
398
|
-
|
|
399
|
-
// Size and alignment statically verified by rust_vec.rs.
|
|
400
|
-
std::array<std::uintptr_t, 3> repr;
|
|
401
|
-
};
|
|
402
|
-
#endif // CXXBRIDGE1_RUST_VEC
|
|
403
|
-
|
|
404
|
-
#ifndef CXXBRIDGE1_RUST_FN
|
|
405
|
-
// https://cxx.rs/binding/fn.html
|
|
406
|
-
template <typename Signature>
|
|
407
|
-
class Fn;
|
|
408
|
-
|
|
409
|
-
template <typename Ret, typename... Args>
|
|
410
|
-
class Fn<Ret(Args...)> final {
|
|
411
|
-
public:
|
|
412
|
-
Ret operator()(Args... args) const noexcept;
|
|
413
|
-
Fn operator*() const noexcept;
|
|
414
|
-
|
|
415
|
-
private:
|
|
416
|
-
Ret (*trampoline)(Args..., void *fn) noexcept;
|
|
417
|
-
void *fn;
|
|
418
|
-
};
|
|
419
|
-
#endif // CXXBRIDGE1_RUST_FN
|
|
420
|
-
|
|
421
|
-
#ifndef CXXBRIDGE1_RUST_ERROR
|
|
422
|
-
#define CXXBRIDGE1_RUST_ERROR
|
|
423
|
-
// https://cxx.rs/binding/result.html
|
|
424
|
-
class Error final : public std::exception {
|
|
425
|
-
public:
|
|
426
|
-
Error(const Error &);
|
|
427
|
-
Error(Error &&) noexcept;
|
|
428
|
-
~Error() noexcept override;
|
|
429
|
-
|
|
430
|
-
Error &operator=(const Error &) &;
|
|
431
|
-
Error &operator=(Error &&) & noexcept;
|
|
432
|
-
|
|
433
|
-
const char *what() const noexcept override;
|
|
434
|
-
|
|
435
|
-
private:
|
|
436
|
-
Error() noexcept = default;
|
|
437
|
-
friend impl<Error>;
|
|
438
|
-
const char *msg;
|
|
439
|
-
std::size_t len;
|
|
440
|
-
};
|
|
441
|
-
#endif // CXXBRIDGE1_RUST_ERROR
|
|
442
|
-
|
|
443
|
-
#ifndef CXXBRIDGE1_RUST_ISIZE
|
|
444
|
-
#define CXXBRIDGE1_RUST_ISIZE
|
|
445
|
-
#if defined(_WIN32)
|
|
446
|
-
using isize = SSIZE_T;
|
|
447
|
-
#else
|
|
448
|
-
using isize = ssize_t;
|
|
449
|
-
#endif
|
|
450
|
-
#endif // CXXBRIDGE1_RUST_ISIZE
|
|
451
|
-
|
|
452
|
-
std::ostream &operator<<(std::ostream &, const String &);
|
|
453
|
-
std::ostream &operator<<(std::ostream &, const Str &);
|
|
454
|
-
|
|
455
|
-
#ifndef CXXBRIDGE1_RUST_OPAQUE
|
|
456
|
-
#define CXXBRIDGE1_RUST_OPAQUE
|
|
457
|
-
// Base class of generated opaque Rust types.
|
|
458
|
-
class Opaque {
|
|
459
|
-
public:
|
|
460
|
-
Opaque() = delete;
|
|
461
|
-
Opaque(const Opaque &) = delete;
|
|
462
|
-
~Opaque() = delete;
|
|
463
|
-
};
|
|
464
|
-
#endif // CXXBRIDGE1_RUST_OPAQUE
|
|
465
|
-
|
|
466
|
-
template <typename T>
|
|
467
|
-
std::size_t size_of();
|
|
468
|
-
template <typename T>
|
|
469
|
-
std::size_t align_of();
|
|
470
|
-
|
|
471
|
-
// IsRelocatable<T> is used in assertions that a C++ type passed by value
|
|
472
|
-
// between Rust and C++ is soundly relocatable by Rust.
|
|
473
|
-
//
|
|
474
|
-
// There may be legitimate reasons to opt out of the check for support of types
|
|
475
|
-
// that the programmer knows are soundly Rust-movable despite not being
|
|
476
|
-
// recognized as such by the C++ type system due to a move constructor or
|
|
477
|
-
// destructor. To opt out of the relocatability check, do either of the
|
|
478
|
-
// following things in any header used by `include!` in the bridge.
|
|
479
|
-
//
|
|
480
|
-
// --- if you define the type:
|
|
481
|
-
// struct MyType {
|
|
482
|
-
// ...
|
|
483
|
-
// + using IsRelocatable = std::true_type;
|
|
484
|
-
// };
|
|
485
|
-
//
|
|
486
|
-
// --- otherwise:
|
|
487
|
-
// + template <>
|
|
488
|
-
// + struct rust::IsRelocatable<MyType> : std::true_type {};
|
|
489
|
-
template <typename T>
|
|
490
|
-
struct IsRelocatable;
|
|
491
|
-
|
|
492
|
-
using u8 = std::uint8_t;
|
|
493
|
-
using u16 = std::uint16_t;
|
|
494
|
-
using u32 = std::uint32_t;
|
|
495
|
-
using u64 = std::uint64_t;
|
|
496
|
-
using usize = std::size_t; // see static asserts in cxx.cc
|
|
497
|
-
using i8 = std::int8_t;
|
|
498
|
-
using i16 = std::int16_t;
|
|
499
|
-
using i32 = std::int32_t;
|
|
500
|
-
using i64 = std::int64_t;
|
|
501
|
-
using f32 = float;
|
|
502
|
-
using f64 = double;
|
|
503
|
-
|
|
504
|
-
// Snake case aliases for use in code that uses this style for type names.
|
|
505
|
-
using string = String;
|
|
506
|
-
using str = Str;
|
|
507
|
-
template <typename T>
|
|
508
|
-
using slice = Slice<T>;
|
|
509
|
-
template <typename T>
|
|
510
|
-
using box = Box<T>;
|
|
511
|
-
template <typename T>
|
|
512
|
-
using vec = Vec<T>;
|
|
513
|
-
using error = Error;
|
|
514
|
-
template <typename Signature>
|
|
515
|
-
using fn = Fn<Signature>;
|
|
516
|
-
template <typename T>
|
|
517
|
-
using is_relocatable = IsRelocatable<T>;
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
522
|
-
/// end public API, begin implementation details
|
|
523
|
-
|
|
524
|
-
#ifndef CXXBRIDGE1_PANIC
|
|
525
|
-
#define CXXBRIDGE1_PANIC
|
|
526
|
-
template <typename Exception>
|
|
527
|
-
void panic [[noreturn]] (const char *msg);
|
|
528
|
-
#endif // CXXBRIDGE1_PANIC
|
|
529
|
-
|
|
530
|
-
#ifndef CXXBRIDGE1_RUST_FN
|
|
531
|
-
#define CXXBRIDGE1_RUST_FN
|
|
532
|
-
template <typename Ret, typename... Args>
|
|
533
|
-
Ret Fn<Ret(Args...)>::operator()(Args... args) const noexcept {
|
|
534
|
-
return (*this->trampoline)(std::forward<Args>(args)..., this->fn);
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
template <typename Ret, typename... Args>
|
|
538
|
-
Fn<Ret(Args...)> Fn<Ret(Args...)>::operator*() const noexcept {
|
|
539
|
-
return *this;
|
|
540
|
-
}
|
|
541
|
-
#endif // CXXBRIDGE1_RUST_FN
|
|
542
|
-
|
|
543
|
-
#ifndef CXXBRIDGE1_RUST_BITCOPY_T
|
|
544
|
-
#define CXXBRIDGE1_RUST_BITCOPY_T
|
|
545
|
-
struct unsafe_bitcopy_t final {
|
|
546
|
-
explicit unsafe_bitcopy_t() = default;
|
|
547
|
-
};
|
|
548
|
-
#endif // CXXBRIDGE1_RUST_BITCOPY_T
|
|
549
|
-
|
|
550
|
-
#ifndef CXXBRIDGE1_RUST_BITCOPY
|
|
551
|
-
#define CXXBRIDGE1_RUST_BITCOPY
|
|
552
|
-
constexpr unsafe_bitcopy_t unsafe_bitcopy{};
|
|
553
|
-
#endif // CXXBRIDGE1_RUST_BITCOPY
|
|
554
|
-
|
|
555
|
-
#ifndef CXXBRIDGE1_RUST_SLICE
|
|
556
|
-
#define CXXBRIDGE1_RUST_SLICE
|
|
557
|
-
template <typename T>
|
|
558
|
-
Slice<T>::Slice() noexcept {
|
|
559
|
-
sliceInit(this, reinterpret_cast<void *>(align_of<T>()), 0);
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
template <typename T>
|
|
563
|
-
Slice<T>::Slice(T *s, std::size_t count) noexcept {
|
|
564
|
-
assert(s != nullptr || count == 0);
|
|
565
|
-
sliceInit(this,
|
|
566
|
-
s == nullptr && count == 0
|
|
567
|
-
? reinterpret_cast<void *>(align_of<T>())
|
|
568
|
-
: const_cast<typename std::remove_const<T>::type *>(s),
|
|
569
|
-
count);
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
template <typename T>
|
|
573
|
-
T *Slice<T>::data() const noexcept {
|
|
574
|
-
return reinterpret_cast<T *>(slicePtr(this));
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
template <typename T>
|
|
578
|
-
std::size_t Slice<T>::size() const noexcept {
|
|
579
|
-
return sliceLen(this);
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
template <typename T>
|
|
583
|
-
std::size_t Slice<T>::length() const noexcept {
|
|
584
|
-
return this->size();
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
template <typename T>
|
|
588
|
-
bool Slice<T>::empty() const noexcept {
|
|
589
|
-
return this->size() == 0;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
template <typename T>
|
|
593
|
-
T &Slice<T>::operator[](std::size_t n) const noexcept {
|
|
594
|
-
assert(n < this->size());
|
|
595
|
-
auto ptr = static_cast<char *>(slicePtr(this)) + size_of<T>() * n;
|
|
596
|
-
return *reinterpret_cast<T *>(ptr);
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
template <typename T>
|
|
600
|
-
T &Slice<T>::at(std::size_t n) const {
|
|
601
|
-
if (n >= this->size()) {
|
|
602
|
-
panic<std::out_of_range>("rust::Slice index out of range");
|
|
603
|
-
}
|
|
604
|
-
return (*this)[n];
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
template <typename T>
|
|
608
|
-
T &Slice<T>::front() const noexcept {
|
|
609
|
-
assert(!this->empty());
|
|
610
|
-
return (*this)[0];
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
template <typename T>
|
|
614
|
-
T &Slice<T>::back() const noexcept {
|
|
615
|
-
assert(!this->empty());
|
|
616
|
-
return (*this)[this->size() - 1];
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
template <typename T>
|
|
620
|
-
typename Slice<T>::iterator::reference
|
|
621
|
-
Slice<T>::iterator::operator*() const noexcept {
|
|
622
|
-
return *static_cast<T *>(this->pos);
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
template <typename T>
|
|
626
|
-
typename Slice<T>::iterator::pointer
|
|
627
|
-
Slice<T>::iterator::operator->() const noexcept {
|
|
628
|
-
return static_cast<T *>(this->pos);
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
template <typename T>
|
|
632
|
-
typename Slice<T>::iterator::reference Slice<T>::iterator::operator[](
|
|
633
|
-
typename Slice<T>::iterator::difference_type n) const noexcept {
|
|
634
|
-
auto ptr = static_cast<char *>(this->pos) + this->stride * n;
|
|
635
|
-
return *reinterpret_cast<T *>(ptr);
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
template <typename T>
|
|
639
|
-
typename Slice<T>::iterator &Slice<T>::iterator::operator++() noexcept {
|
|
640
|
-
this->pos = static_cast<char *>(this->pos) + this->stride;
|
|
641
|
-
return *this;
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
template <typename T>
|
|
645
|
-
typename Slice<T>::iterator Slice<T>::iterator::operator++(int) noexcept {
|
|
646
|
-
auto ret = iterator(*this);
|
|
647
|
-
this->pos = static_cast<char *>(this->pos) + this->stride;
|
|
648
|
-
return ret;
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
template <typename T>
|
|
652
|
-
typename Slice<T>::iterator &Slice<T>::iterator::operator--() noexcept {
|
|
653
|
-
this->pos = static_cast<char *>(this->pos) - this->stride;
|
|
654
|
-
return *this;
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
template <typename T>
|
|
658
|
-
typename Slice<T>::iterator Slice<T>::iterator::operator--(int) noexcept {
|
|
659
|
-
auto ret = iterator(*this);
|
|
660
|
-
this->pos = static_cast<char *>(this->pos) - this->stride;
|
|
661
|
-
return ret;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
template <typename T>
|
|
665
|
-
typename Slice<T>::iterator &Slice<T>::iterator::operator+=(
|
|
666
|
-
typename Slice<T>::iterator::difference_type n) noexcept {
|
|
667
|
-
this->pos = static_cast<char *>(this->pos) + this->stride * n;
|
|
668
|
-
return *this;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
template <typename T>
|
|
672
|
-
typename Slice<T>::iterator &Slice<T>::iterator::operator-=(
|
|
673
|
-
typename Slice<T>::iterator::difference_type n) noexcept {
|
|
674
|
-
this->pos = static_cast<char *>(this->pos) - this->stride * n;
|
|
675
|
-
return *this;
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
template <typename T>
|
|
679
|
-
typename Slice<T>::iterator Slice<T>::iterator::operator+(
|
|
680
|
-
typename Slice<T>::iterator::difference_type n) const noexcept {
|
|
681
|
-
auto ret = iterator(*this);
|
|
682
|
-
ret.pos = static_cast<char *>(this->pos) + this->stride * n;
|
|
683
|
-
return ret;
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
template <typename T>
|
|
687
|
-
typename Slice<T>::iterator Slice<T>::iterator::operator-(
|
|
688
|
-
typename Slice<T>::iterator::difference_type n) const noexcept {
|
|
689
|
-
auto ret = iterator(*this);
|
|
690
|
-
ret.pos = static_cast<char *>(this->pos) - this->stride * n;
|
|
691
|
-
return ret;
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
template <typename T>
|
|
695
|
-
typename Slice<T>::iterator::difference_type
|
|
696
|
-
Slice<T>::iterator::operator-(const iterator &other) const noexcept {
|
|
697
|
-
auto diff = std::distance(static_cast<char *>(other.pos),
|
|
698
|
-
static_cast<char *>(this->pos));
|
|
699
|
-
return diff / static_cast<typename Slice<T>::iterator::difference_type>(
|
|
700
|
-
this->stride);
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
template <typename T>
|
|
704
|
-
bool Slice<T>::iterator::operator==(const iterator &other) const noexcept {
|
|
705
|
-
return this->pos == other.pos;
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
template <typename T>
|
|
709
|
-
bool Slice<T>::iterator::operator!=(const iterator &other) const noexcept {
|
|
710
|
-
return this->pos != other.pos;
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
template <typename T>
|
|
714
|
-
bool Slice<T>::iterator::operator<(const iterator &other) const noexcept {
|
|
715
|
-
return this->pos < other.pos;
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
template <typename T>
|
|
719
|
-
bool Slice<T>::iterator::operator<=(const iterator &other) const noexcept {
|
|
720
|
-
return this->pos <= other.pos;
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
template <typename T>
|
|
724
|
-
bool Slice<T>::iterator::operator>(const iterator &other) const noexcept {
|
|
725
|
-
return this->pos > other.pos;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
template <typename T>
|
|
729
|
-
bool Slice<T>::iterator::operator>=(const iterator &other) const noexcept {
|
|
730
|
-
return this->pos >= other.pos;
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
template <typename T>
|
|
734
|
-
typename Slice<T>::iterator Slice<T>::begin() const noexcept {
|
|
735
|
-
iterator it;
|
|
736
|
-
it.pos = slicePtr(this);
|
|
737
|
-
it.stride = size_of<T>();
|
|
738
|
-
return it;
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
template <typename T>
|
|
742
|
-
typename Slice<T>::iterator Slice<T>::end() const noexcept {
|
|
743
|
-
iterator it = this->begin();
|
|
744
|
-
it.pos = static_cast<char *>(it.pos) + it.stride * this->size();
|
|
745
|
-
return it;
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
template <typename T>
|
|
749
|
-
void Slice<T>::swap(Slice &rhs) noexcept {
|
|
750
|
-
std::swap(*this, rhs);
|
|
751
|
-
}
|
|
752
|
-
#endif // CXXBRIDGE1_RUST_SLICE
|
|
753
|
-
|
|
754
|
-
#ifndef CXXBRIDGE1_RUST_BOX
|
|
755
|
-
#define CXXBRIDGE1_RUST_BOX
|
|
756
|
-
template <typename T>
|
|
757
|
-
class Box<T>::uninit {};
|
|
758
|
-
|
|
759
|
-
template <typename T>
|
|
760
|
-
class Box<T>::allocation {
|
|
761
|
-
static T *alloc() noexcept;
|
|
762
|
-
static void dealloc(T *) noexcept;
|
|
763
|
-
|
|
764
|
-
public:
|
|
765
|
-
allocation() noexcept : ptr(alloc()) {}
|
|
766
|
-
~allocation() noexcept {
|
|
767
|
-
if (this->ptr) {
|
|
768
|
-
dealloc(this->ptr);
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
T *ptr;
|
|
772
|
-
};
|
|
773
|
-
|
|
774
|
-
template <typename T>
|
|
775
|
-
Box<T>::Box(Box &&other) noexcept : ptr(other.ptr) {
|
|
776
|
-
other.ptr = nullptr;
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
template <typename T>
|
|
780
|
-
Box<T>::Box(const T &val) {
|
|
781
|
-
allocation alloc;
|
|
782
|
-
::new (alloc.ptr) T(val);
|
|
783
|
-
this->ptr = alloc.ptr;
|
|
784
|
-
alloc.ptr = nullptr;
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
template <typename T>
|
|
788
|
-
Box<T>::Box(T &&val) {
|
|
789
|
-
allocation alloc;
|
|
790
|
-
::new (alloc.ptr) T(std::move(val));
|
|
791
|
-
this->ptr = alloc.ptr;
|
|
792
|
-
alloc.ptr = nullptr;
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
template <typename T>
|
|
796
|
-
Box<T>::~Box() noexcept {
|
|
797
|
-
if (this->ptr) {
|
|
798
|
-
this->drop();
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
template <typename T>
|
|
803
|
-
Box<T> &Box<T>::operator=(Box &&other) & noexcept {
|
|
804
|
-
if (this->ptr) {
|
|
805
|
-
this->drop();
|
|
806
|
-
}
|
|
807
|
-
this->ptr = other.ptr;
|
|
808
|
-
other.ptr = nullptr;
|
|
809
|
-
return *this;
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
template <typename T>
|
|
813
|
-
const T *Box<T>::operator->() const noexcept {
|
|
814
|
-
return this->ptr;
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
template <typename T>
|
|
818
|
-
const T &Box<T>::operator*() const noexcept {
|
|
819
|
-
return *this->ptr;
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
template <typename T>
|
|
823
|
-
T *Box<T>::operator->() noexcept {
|
|
824
|
-
return this->ptr;
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
template <typename T>
|
|
828
|
-
T &Box<T>::operator*() noexcept {
|
|
829
|
-
return *this->ptr;
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
template <typename T>
|
|
833
|
-
template <typename... Fields>
|
|
834
|
-
Box<T> Box<T>::in_place(Fields &&...fields) {
|
|
835
|
-
allocation alloc;
|
|
836
|
-
auto ptr = alloc.ptr;
|
|
837
|
-
::new (ptr) T{std::forward<Fields>(fields)...};
|
|
838
|
-
alloc.ptr = nullptr;
|
|
839
|
-
return from_raw(ptr);
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
template <typename T>
|
|
843
|
-
void Box<T>::swap(Box &rhs) noexcept {
|
|
844
|
-
using std::swap;
|
|
845
|
-
swap(this->ptr, rhs.ptr);
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
template <typename T>
|
|
849
|
-
Box<T> Box<T>::from_raw(T *raw) noexcept {
|
|
850
|
-
Box box = uninit{};
|
|
851
|
-
box.ptr = raw;
|
|
852
|
-
return box;
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
template <typename T>
|
|
856
|
-
T *Box<T>::into_raw() noexcept {
|
|
857
|
-
T *raw = this->ptr;
|
|
858
|
-
this->ptr = nullptr;
|
|
859
|
-
return raw;
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
template <typename T>
|
|
863
|
-
Box<T>::Box(uninit) noexcept {}
|
|
864
|
-
#endif // CXXBRIDGE1_RUST_BOX
|
|
865
|
-
|
|
866
|
-
#ifndef CXXBRIDGE1_RUST_VEC
|
|
867
|
-
#define CXXBRIDGE1_RUST_VEC
|
|
868
|
-
template <typename T>
|
|
869
|
-
Vec<T>::Vec(std::initializer_list<T> init) : Vec{} {
|
|
870
|
-
this->reserve_total(init.size());
|
|
871
|
-
std::move(init.begin(), init.end(), std::back_inserter(*this));
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
template <typename T>
|
|
875
|
-
Vec<T>::Vec(const Vec &other) : Vec() {
|
|
876
|
-
this->reserve_total(other.size());
|
|
877
|
-
std::copy(other.begin(), other.end(), std::back_inserter(*this));
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
template <typename T>
|
|
881
|
-
Vec<T>::Vec(Vec &&other) noexcept : repr(other.repr) {
|
|
882
|
-
new (&other) Vec();
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
template <typename T>
|
|
886
|
-
Vec<T>::~Vec() noexcept {
|
|
887
|
-
this->drop();
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
template <typename T>
|
|
891
|
-
Vec<T> &Vec<T>::operator=(Vec &&other) & noexcept {
|
|
892
|
-
this->drop();
|
|
893
|
-
this->repr = other.repr;
|
|
894
|
-
new (&other) Vec();
|
|
895
|
-
return *this;
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
template <typename T>
|
|
899
|
-
Vec<T> &Vec<T>::operator=(const Vec &other) & {
|
|
900
|
-
if (this != &other) {
|
|
901
|
-
this->drop();
|
|
902
|
-
new (this) Vec(other);
|
|
903
|
-
}
|
|
904
|
-
return *this;
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
template <typename T>
|
|
908
|
-
bool Vec<T>::empty() const noexcept {
|
|
909
|
-
return this->size() == 0;
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
template <typename T>
|
|
913
|
-
T *Vec<T>::data() noexcept {
|
|
914
|
-
return const_cast<T *>(const_cast<const Vec<T> *>(this)->data());
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
template <typename T>
|
|
918
|
-
const T &Vec<T>::operator[](std::size_t n) const noexcept {
|
|
919
|
-
assert(n < this->size());
|
|
920
|
-
auto data = reinterpret_cast<const char *>(this->data());
|
|
921
|
-
return *reinterpret_cast<const T *>(data + n * size_of<T>());
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
template <typename T>
|
|
925
|
-
const T &Vec<T>::at(std::size_t n) const {
|
|
926
|
-
if (n >= this->size()) {
|
|
927
|
-
panic<std::out_of_range>("rust::Vec index out of range");
|
|
928
|
-
}
|
|
929
|
-
return (*this)[n];
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
template <typename T>
|
|
933
|
-
const T &Vec<T>::front() const noexcept {
|
|
934
|
-
assert(!this->empty());
|
|
935
|
-
return (*this)[0];
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
template <typename T>
|
|
939
|
-
const T &Vec<T>::back() const noexcept {
|
|
940
|
-
assert(!this->empty());
|
|
941
|
-
return (*this)[this->size() - 1];
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
template <typename T>
|
|
945
|
-
T &Vec<T>::operator[](std::size_t n) noexcept {
|
|
946
|
-
assert(n < this->size());
|
|
947
|
-
auto data = reinterpret_cast<char *>(this->data());
|
|
948
|
-
return *reinterpret_cast<T *>(data + n * size_of<T>());
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
template <typename T>
|
|
952
|
-
T &Vec<T>::at(std::size_t n) {
|
|
953
|
-
if (n >= this->size()) {
|
|
954
|
-
panic<std::out_of_range>("rust::Vec index out of range");
|
|
955
|
-
}
|
|
956
|
-
return (*this)[n];
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
template <typename T>
|
|
960
|
-
T &Vec<T>::front() noexcept {
|
|
961
|
-
assert(!this->empty());
|
|
962
|
-
return (*this)[0];
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
template <typename T>
|
|
966
|
-
T &Vec<T>::back() noexcept {
|
|
967
|
-
assert(!this->empty());
|
|
968
|
-
return (*this)[this->size() - 1];
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
template <typename T>
|
|
972
|
-
void Vec<T>::reserve(std::size_t new_cap) {
|
|
973
|
-
this->reserve_total(new_cap);
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
template <typename T>
|
|
977
|
-
void Vec<T>::push_back(const T &value) {
|
|
978
|
-
this->emplace_back(value);
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
template <typename T>
|
|
982
|
-
void Vec<T>::push_back(T &&value) {
|
|
983
|
-
this->emplace_back(std::move(value));
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
template <typename T>
|
|
987
|
-
template <typename... Args>
|
|
988
|
-
void Vec<T>::emplace_back(Args &&...args) {
|
|
989
|
-
auto size = this->size();
|
|
990
|
-
this->reserve_total(size + 1);
|
|
991
|
-
::new (reinterpret_cast<T *>(reinterpret_cast<char *>(this->data()) +
|
|
992
|
-
size * size_of<T>()))
|
|
993
|
-
T(std::forward<Args>(args)...);
|
|
994
|
-
this->set_len(size + 1);
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
template <typename T>
|
|
998
|
-
void Vec<T>::clear() {
|
|
999
|
-
this->truncate(0);
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
template <typename T>
|
|
1003
|
-
typename Vec<T>::iterator Vec<T>::begin() noexcept {
|
|
1004
|
-
return Slice<T>(this->data(), this->size()).begin();
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
template <typename T>
|
|
1008
|
-
typename Vec<T>::iterator Vec<T>::end() noexcept {
|
|
1009
|
-
return Slice<T>(this->data(), this->size()).end();
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
template <typename T>
|
|
1013
|
-
typename Vec<T>::const_iterator Vec<T>::begin() const noexcept {
|
|
1014
|
-
return this->cbegin();
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
template <typename T>
|
|
1018
|
-
typename Vec<T>::const_iterator Vec<T>::end() const noexcept {
|
|
1019
|
-
return this->cend();
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
template <typename T>
|
|
1023
|
-
typename Vec<T>::const_iterator Vec<T>::cbegin() const noexcept {
|
|
1024
|
-
return Slice<const T>(this->data(), this->size()).begin();
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
template <typename T>
|
|
1028
|
-
typename Vec<T>::const_iterator Vec<T>::cend() const noexcept {
|
|
1029
|
-
return Slice<const T>(this->data(), this->size()).end();
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
template <typename T>
|
|
1033
|
-
void Vec<T>::swap(Vec &rhs) noexcept {
|
|
1034
|
-
using std::swap;
|
|
1035
|
-
swap(this->repr, rhs.repr);
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
// Internal API only intended for the cxxbridge code generator.
|
|
1039
|
-
template <typename T>
|
|
1040
|
-
Vec<T>::Vec(unsafe_bitcopy_t, const Vec &bits) noexcept : repr(bits.repr) {}
|
|
1041
|
-
#endif // CXXBRIDGE1_RUST_VEC
|
|
1042
|
-
|
|
1043
|
-
#ifndef CXXBRIDGE1_IS_COMPLETE
|
|
1044
|
-
#define CXXBRIDGE1_IS_COMPLETE
|
|
1045
|
-
namespace detail {
|
|
1046
|
-
namespace {
|
|
1047
|
-
template <typename T, typename = std::size_t>
|
|
1048
|
-
struct is_complete : std::false_type {};
|
|
1049
|
-
template <typename T>
|
|
1050
|
-
struct is_complete<T, decltype(sizeof(T))> : std::true_type {};
|
|
1051
|
-
} // namespace
|
|
1052
|
-
} // namespace detail
|
|
1053
|
-
#endif // CXXBRIDGE1_IS_COMPLETE
|
|
1054
|
-
|
|
1055
|
-
#ifndef CXXBRIDGE1_LAYOUT
|
|
1056
|
-
#define CXXBRIDGE1_LAYOUT
|
|
1057
|
-
class layout {
|
|
1058
|
-
template <typename T>
|
|
1059
|
-
friend std::size_t size_of();
|
|
1060
|
-
template <typename T>
|
|
1061
|
-
friend std::size_t align_of();
|
|
1062
|
-
template <typename T>
|
|
1063
|
-
static typename std::enable_if<std::is_base_of<Opaque, T>::value,
|
|
1064
|
-
std::size_t>::type
|
|
1065
|
-
do_size_of() {
|
|
1066
|
-
return T::layout::size();
|
|
1067
|
-
}
|
|
1068
|
-
template <typename T>
|
|
1069
|
-
static typename std::enable_if<!std::is_base_of<Opaque, T>::value,
|
|
1070
|
-
std::size_t>::type
|
|
1071
|
-
do_size_of() {
|
|
1072
|
-
return sizeof(T);
|
|
1073
|
-
}
|
|
1074
|
-
template <typename T>
|
|
1075
|
-
static
|
|
1076
|
-
typename std::enable_if<detail::is_complete<T>::value, std::size_t>::type
|
|
1077
|
-
size_of() {
|
|
1078
|
-
return do_size_of<T>();
|
|
1079
|
-
}
|
|
1080
|
-
template <typename T>
|
|
1081
|
-
static typename std::enable_if<std::is_base_of<Opaque, T>::value,
|
|
1082
|
-
std::size_t>::type
|
|
1083
|
-
do_align_of() {
|
|
1084
|
-
return T::layout::align();
|
|
1085
|
-
}
|
|
1086
|
-
template <typename T>
|
|
1087
|
-
static typename std::enable_if<!std::is_base_of<Opaque, T>::value,
|
|
1088
|
-
std::size_t>::type
|
|
1089
|
-
do_align_of() {
|
|
1090
|
-
return alignof(T);
|
|
1091
|
-
}
|
|
1092
|
-
template <typename T>
|
|
1093
|
-
static
|
|
1094
|
-
typename std::enable_if<detail::is_complete<T>::value, std::size_t>::type
|
|
1095
|
-
align_of() {
|
|
1096
|
-
return do_align_of<T>();
|
|
1097
|
-
}
|
|
1098
|
-
};
|
|
1099
|
-
|
|
1100
|
-
template <typename T>
|
|
1101
|
-
std::size_t size_of() {
|
|
1102
|
-
return layout::size_of<T>();
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
template <typename T>
|
|
1106
|
-
std::size_t align_of() {
|
|
1107
|
-
return layout::align_of<T>();
|
|
1108
|
-
}
|
|
1109
|
-
#endif // CXXBRIDGE1_LAYOUT
|
|
1110
|
-
|
|
1111
|
-
#ifndef CXXBRIDGE1_RELOCATABLE
|
|
1112
|
-
#define CXXBRIDGE1_RELOCATABLE
|
|
1113
|
-
namespace detail {
|
|
1114
|
-
template <typename... Ts>
|
|
1115
|
-
struct make_void {
|
|
1116
|
-
using type = void;
|
|
1117
|
-
};
|
|
1118
|
-
|
|
1119
|
-
template <typename... Ts>
|
|
1120
|
-
using void_t = typename make_void<Ts...>::type;
|
|
1121
|
-
|
|
1122
|
-
template <typename Void, template <typename...> class, typename...>
|
|
1123
|
-
struct detect : std::false_type {};
|
|
1124
|
-
template <template <typename...> class T, typename... A>
|
|
1125
|
-
struct detect<void_t<T<A...>>, T, A...> : std::true_type {};
|
|
1126
|
-
|
|
1127
|
-
template <template <typename...> class T, typename... A>
|
|
1128
|
-
using is_detected = detect<void, T, A...>;
|
|
1129
|
-
|
|
1130
|
-
template <typename T>
|
|
1131
|
-
using detect_IsRelocatable = typename T::IsRelocatable;
|
|
1132
|
-
|
|
1133
|
-
template <typename T>
|
|
1134
|
-
struct get_IsRelocatable
|
|
1135
|
-
: std::is_same<typename T::IsRelocatable, std::true_type> {};
|
|
1136
|
-
} // namespace detail
|
|
1137
|
-
|
|
1138
|
-
template <typename T>
|
|
1139
|
-
struct IsRelocatable
|
|
1140
|
-
: std::conditional<
|
|
1141
|
-
detail::is_detected<detail::detect_IsRelocatable, T>::value,
|
|
1142
|
-
detail::get_IsRelocatable<T>,
|
|
1143
|
-
std::integral_constant<
|
|
1144
|
-
bool, std::is_trivially_move_constructible<T>::value &&
|
|
1145
|
-
std::is_trivially_destructible<T>::value>>::type {};
|
|
1146
|
-
#endif // CXXBRIDGE1_RELOCATABLE
|
|
1147
|
-
|
|
1148
|
-
} // namespace cxxbridge1
|
|
1149
|
-
} // namespace rust
|