| David Tolnay | 736cbca | 2020-03-11 16:49:18 -0700 | [diff] [blame] | 1 | #include "../include/cxx.h" |
| David Tolnay | ff86dce | 2020-11-29 19:45:13 -0800 | [diff] [blame] | 2 | #include <algorithm> |
| David Tolnay | 54b1322 | 2020-10-30 20:58:32 -0700 | [diff] [blame] | 3 | #include <cassert> |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 4 | #include <cstring> |
| David Tolnay | 71918ec | 2020-04-11 21:52:09 -0700 | [diff] [blame] | 5 | #include <exception> |
| David Tolnay | 001102a | 2020-03-01 20:05:04 -0800 | [diff] [blame] | 6 | #include <iostream> |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 7 | #include <memory> |
| 8 | #include <stdexcept> |
| David Tolnay | 9ed15c6 | 2020-10-31 18:02:03 -0700 | [diff] [blame] | 9 | #include <type_traits> |
| David Tolnay | 37dd7e1 | 2020-04-25 12:51:59 -0700 | [diff] [blame] | 10 | #include <vector> |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 11 | |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 12 | extern "C" { |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 13 | void cxxbridge1$cxx_string$init(std::string *s, const uint8_t *ptr, |
| 14 | size_t len) noexcept { |
| David Tolnay | bb3ff5d | 2020-11-15 19:45:11 -0800 | [diff] [blame] | 15 | new (s) std::string(reinterpret_cast<const char *>(ptr), len); |
| 16 | } |
| 17 | |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 18 | void cxxbridge1$cxx_string$destroy(std::string *s) noexcept { |
| David Tolnay | bb3ff5d | 2020-11-15 19:45:11 -0800 | [diff] [blame] | 19 | using std::string; |
| 20 | s->~string(); |
| 21 | } |
| 22 | |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 23 | const char *cxxbridge1$cxx_string$data(const std::string &s) noexcept { |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 24 | return s.data(); |
| 25 | } |
| 26 | |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 27 | size_t cxxbridge1$cxx_string$length(const std::string &s) noexcept { |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 28 | return s.length(); |
| 29 | } |
| 30 | |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 31 | void cxxbridge1$cxx_string$push(std::string &s, const uint8_t *ptr, |
| 32 | size_t len) noexcept { |
| David Tolnay | 90691f4 | 2020-11-14 20:01:46 -0800 | [diff] [blame] | 33 | s.append(reinterpret_cast<const char *>(ptr), len); |
| 34 | } |
| 35 | |
| David Tolnay | 750755e | 2020-03-01 13:04:08 -0800 | [diff] [blame] | 36 | // rust::String |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 37 | void cxxbridge1$string$new(rust::String *self) noexcept; |
| 38 | void cxxbridge1$string$clone(rust::String *self, |
| 39 | const rust::String &other) noexcept; |
| 40 | bool cxxbridge1$string$from(rust::String *self, const char *ptr, |
| 41 | size_t len) noexcept; |
| 42 | void cxxbridge1$string$drop(rust::String *self) noexcept; |
| 43 | const char *cxxbridge1$string$ptr(const rust::String *self) noexcept; |
| 44 | size_t cxxbridge1$string$len(const rust::String *self) noexcept; |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 45 | |
| David Tolnay | 750755e | 2020-03-01 13:04:08 -0800 | [diff] [blame] | 46 | // rust::Str |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 47 | bool cxxbridge1$str$valid(const char *ptr, size_t len) noexcept; |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 48 | } // extern "C" |
| 49 | |
| David Tolnay | 750755e | 2020-03-01 13:04:08 -0800 | [diff] [blame] | 50 | namespace rust { |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 51 | inline namespace cxxbridge1 { |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 52 | |
| David Tolnay | 521d99d | 2020-08-26 20:45:40 -0700 | [diff] [blame] | 53 | template <typename Exception> |
| 54 | void panic [[noreturn]] (const char *msg) { |
| 55 | #if defined(RUST_CXX_NO_EXCEPTIONS) |
| 56 | std::cerr << "Error: " << msg << ". Aborting." << std::endl; |
| 57 | std::terminate(); |
| 58 | #else |
| 59 | throw Exception(msg); |
| 60 | #endif |
| 61 | } |
| 62 | |
| David Tolnay | b10c4bc | 2020-08-26 21:55:29 -0700 | [diff] [blame] | 63 | template void panic<std::out_of_range>[[noreturn]] (const char *msg); |
| David Tolnay | 521d99d | 2020-08-26 20:45:40 -0700 | [diff] [blame] | 64 | |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 65 | String::String() noexcept { cxxbridge1$string$new(this); } |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 66 | |
| David Tolnay | 5608216 | 2020-03-01 12:57:33 -0800 | [diff] [blame] | 67 | String::String(const String &other) noexcept { |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 68 | cxxbridge1$string$clone(this, other); |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 69 | } |
| 70 | |
| David Tolnay | 1567186 | 2020-11-23 18:13:56 -0800 | [diff] [blame] | 71 | String::String(String &&other) noexcept : repr(other.repr) { |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 72 | cxxbridge1$string$new(&other); |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 73 | } |
| 74 | |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 75 | String::~String() noexcept { cxxbridge1$string$drop(this); } |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 76 | |
| David Tolnay | 032d853 | 2020-10-30 20:47:31 -0700 | [diff] [blame] | 77 | static void initString(String *self, const char *s, size_t len) { |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 78 | if (!cxxbridge1$string$from(self, s, len)) { |
| David Tolnay | 8d32366 | 2020-10-30 19:32:26 -0700 | [diff] [blame] | 79 | panic<std::invalid_argument>("data for rust::String is not utf-8"); |
| 80 | } |
| 81 | } |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 82 | |
| David Tolnay | 032d853 | 2020-10-30 20:47:31 -0700 | [diff] [blame] | 83 | String::String(const std::string &s) { initString(this, s.data(), s.length()); } |
| 84 | |
| David Tolnay | 54b1322 | 2020-10-30 20:58:32 -0700 | [diff] [blame] | 85 | String::String(const char *s) { |
| 86 | assert(s != nullptr); |
| 87 | initString(this, s, std::strlen(s)); |
| 88 | } |
| David Tolnay | c2bbd95 | 2020-07-29 18:15:26 -0700 | [diff] [blame] | 89 | |
| 90 | String::String(const char *s, size_t len) { |
| David Tolnay | 54b1322 | 2020-10-30 20:58:32 -0700 | [diff] [blame] | 91 | assert(s != nullptr || len == 0); |
| David Tolnay | 032d853 | 2020-10-30 20:47:31 -0700 | [diff] [blame] | 92 | initString(this, |
| 93 | s == nullptr && len == 0 ? reinterpret_cast<const char *>(1) : s, |
| 94 | len); |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 95 | } |
| 96 | |
| David Tolnay | 5608216 | 2020-03-01 12:57:33 -0800 | [diff] [blame] | 97 | String &String::operator=(const String &other) noexcept { |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 98 | if (this != &other) { |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 99 | cxxbridge1$string$drop(this); |
| 100 | cxxbridge1$string$clone(this, other); |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 101 | } |
| 102 | return *this; |
| 103 | } |
| 104 | |
| David Tolnay | 5608216 | 2020-03-01 12:57:33 -0800 | [diff] [blame] | 105 | String &String::operator=(String &&other) noexcept { |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 106 | if (this != &other) { |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 107 | cxxbridge1$string$drop(this); |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 108 | this->repr = other.repr; |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 109 | cxxbridge1$string$new(&other); |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 110 | } |
| 111 | return *this; |
| 112 | } |
| 113 | |
| David Tolnay | d9c4ac9 | 2020-03-01 20:33:58 -0800 | [diff] [blame] | 114 | String::operator std::string() const { |
| 115 | return std::string(this->data(), this->size()); |
| 116 | } |
| 117 | |
| David Tolnay | 5608216 | 2020-03-01 12:57:33 -0800 | [diff] [blame] | 118 | const char *String::data() const noexcept { |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 119 | return cxxbridge1$string$ptr(this); |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 120 | } |
| 121 | |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 122 | size_t String::size() const noexcept { return cxxbridge1$string$len(this); } |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 123 | |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 124 | size_t String::length() const noexcept { return cxxbridge1$string$len(this); } |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 125 | |
| David Tolnay | ff7f5fb | 2020-11-25 20:50:32 -0800 | [diff] [blame] | 126 | String::iterator String::begin() noexcept { |
| 127 | return const_cast<char *>(this->data()); |
| 128 | } |
| 129 | |
| 130 | String::iterator String::end() noexcept { |
| 131 | return const_cast<char *>(this->data()) + this->size(); |
| 132 | } |
| 133 | |
| 134 | String::const_iterator String::begin() const noexcept { return this->cbegin(); } |
| 135 | |
| 136 | String::const_iterator String::end() const noexcept { return this->cend(); } |
| 137 | |
| 138 | String::const_iterator String::cbegin() const noexcept { return this->data(); } |
| 139 | |
| 140 | String::const_iterator String::cend() const noexcept { |
| 141 | return this->data() + this->size(); |
| 142 | } |
| 143 | |
| David Tolnay | ff86dce | 2020-11-29 19:45:13 -0800 | [diff] [blame] | 144 | bool String::operator==(const String &rhs) const noexcept { |
| 145 | return rust::Str(*this) == rust::Str(rhs); |
| 146 | } |
| 147 | |
| 148 | bool String::operator!=(const String &rhs) const noexcept { |
| 149 | return rust::Str(*this) != rust::Str(rhs); |
| 150 | } |
| 151 | |
| 152 | bool String::operator<(const String &rhs) const noexcept { |
| 153 | return rust::Str(*this) < rust::Str(rhs); |
| 154 | } |
| 155 | |
| 156 | bool String::operator<=(const String &rhs) const noexcept { |
| 157 | return rust::Str(*this) <= rust::Str(rhs); |
| 158 | } |
| 159 | |
| 160 | bool String::operator>(const String &rhs) const noexcept { |
| 161 | return rust::Str(*this) > rust::Str(rhs); |
| 162 | } |
| 163 | |
| 164 | bool String::operator>=(const String &rhs) const noexcept { |
| 165 | return rust::Str(*this) >= rust::Str(rhs); |
| 166 | } |
| 167 | |
| David Tolnay | d1e2efc | 2020-03-03 22:25:43 -0800 | [diff] [blame] | 168 | String::String(unsafe_bitcopy_t, const String &bits) noexcept |
| 169 | : repr(bits.repr) {} |
| 170 | |
| David Tolnay | 5608216 | 2020-03-01 12:57:33 -0800 | [diff] [blame] | 171 | std::ostream &operator<<(std::ostream &os, const String &s) { |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 172 | os.write(s.data(), s.size()); |
| 173 | return os; |
| 174 | } |
| 175 | |
| David Tolnay | 5df1f06 | 2020-10-31 12:31:10 -0700 | [diff] [blame] | 176 | Str::Str() noexcept : ptr(reinterpret_cast<const char *>(1)), len(0) {} |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 177 | |
| David Tolnay | 828e513 | 2020-11-29 20:40:40 -0800 | [diff] [blame] | 178 | Str::Str(const String &s) noexcept : ptr(s.data()), len(s.length()) {} |
| 179 | |
| David Tolnay | 5df1f06 | 2020-10-31 12:31:10 -0700 | [diff] [blame] | 180 | static void initStr(const char *ptr, size_t len) { |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 181 | if (!cxxbridge1$str$valid(ptr, len)) { |
| David Tolnay | 8d32366 | 2020-10-30 19:32:26 -0700 | [diff] [blame] | 182 | panic<std::invalid_argument>("data for rust::Str is not utf-8"); |
| 183 | } |
| 184 | } |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 185 | |
| David Tolnay | 5df1f06 | 2020-10-31 12:31:10 -0700 | [diff] [blame] | 186 | Str::Str(const std::string &s) : ptr(s.data()), len(s.length()) { |
| 187 | initStr(this->ptr, this->len); |
| David Tolnay | 8d32366 | 2020-10-30 19:32:26 -0700 | [diff] [blame] | 188 | } |
| David Tolnay | 894c5e4 | 2020-07-29 18:20:00 -0700 | [diff] [blame] | 189 | |
| David Tolnay | 5df1f06 | 2020-10-31 12:31:10 -0700 | [diff] [blame] | 190 | Str::Str(const char *s) : ptr(s), len(std::strlen(s)) { |
| David Tolnay | 54b1322 | 2020-10-30 20:58:32 -0700 | [diff] [blame] | 191 | assert(s != nullptr); |
| David Tolnay | 5df1f06 | 2020-10-31 12:31:10 -0700 | [diff] [blame] | 192 | initStr(this->ptr, this->len); |
| David Tolnay | 54b1322 | 2020-10-30 20:58:32 -0700 | [diff] [blame] | 193 | } |
| David Tolnay | 032d853 | 2020-10-30 20:47:31 -0700 | [diff] [blame] | 194 | |
| David Tolnay | 8d32366 | 2020-10-30 19:32:26 -0700 | [diff] [blame] | 195 | Str::Str(const char *s, size_t len) |
| David Tolnay | 5df1f06 | 2020-10-31 12:31:10 -0700 | [diff] [blame] | 196 | : ptr(s == nullptr && len == 0 ? reinterpret_cast<const char *>(1) : s), |
| 197 | len(len) { |
| David Tolnay | 54b1322 | 2020-10-30 20:58:32 -0700 | [diff] [blame] | 198 | assert(s != nullptr || len == 0); |
| David Tolnay | 5df1f06 | 2020-10-31 12:31:10 -0700 | [diff] [blame] | 199 | initStr(this->ptr, this->len); |
| David Tolnay | d9c4ac9 | 2020-03-01 20:33:58 -0800 | [diff] [blame] | 200 | } |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 201 | |
| David Tolnay | 09dbe75 | 2020-03-01 13:00:40 -0800 | [diff] [blame] | 202 | Str::operator std::string() const { |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 203 | return std::string(this->data(), this->size()); |
| 204 | } |
| 205 | |
| David Tolnay | ff7f5fb | 2020-11-25 20:50:32 -0800 | [diff] [blame] | 206 | Str::const_iterator Str::begin() const noexcept { return this->cbegin(); } |
| 207 | |
| 208 | Str::const_iterator Str::end() const noexcept { return this->cend(); } |
| 209 | |
| 210 | Str::const_iterator Str::cbegin() const noexcept { return this->ptr; } |
| 211 | |
| 212 | Str::const_iterator Str::cend() const noexcept { return this->ptr + this->len; } |
| 213 | |
| David Tolnay | ff86dce | 2020-11-29 19:45:13 -0800 | [diff] [blame] | 214 | bool Str::operator==(const Str &rhs) const noexcept { |
| 215 | return this->len == rhs.len && |
| 216 | std::equal(this->begin(), this->end(), rhs.begin()); |
| 217 | } |
| 218 | |
| 219 | bool Str::operator!=(const Str &rhs) const noexcept { return !(*this == rhs); } |
| 220 | |
| 221 | bool Str::operator<(const Str &rhs) const noexcept { |
| 222 | return std::lexicographical_compare(this->begin(), this->end(), rhs.begin(), |
| 223 | rhs.end()); |
| 224 | } |
| 225 | |
| 226 | bool Str::operator<=(const Str &rhs) const noexcept { |
| 227 | // std::mismatch(this->begin(), this->end(), rhs.begin(), rhs.end()), except |
| 228 | // without Undefined Behavior on C++11 if rhs is shorter than *this. |
| 229 | const_iterator liter = this->begin(), lend = this->end(), riter = rhs.begin(), |
| 230 | rend = rhs.end(); |
| 231 | while (liter != lend && riter != rend && *liter == *riter) { |
| 232 | ++liter, ++riter; |
| 233 | } |
| 234 | if (liter == lend) { |
| 235 | return true; // equal or *this is a prefix of rhs |
| 236 | } else if (riter == rend) { |
| 237 | return false; // rhs is a prefix of *this |
| 238 | } else { |
| 239 | return *liter <= *riter; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | bool Str::operator>(const Str &rhs) const noexcept { return rhs < *this; } |
| 244 | |
| 245 | bool Str::operator>=(const Str &rhs) const noexcept { return rhs <= *this; } |
| 246 | |
| David Tolnay | 09dbe75 | 2020-03-01 13:00:40 -0800 | [diff] [blame] | 247 | std::ostream &operator<<(std::ostream &os, const Str &s) { |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 248 | os.write(s.data(), s.size()); |
| 249 | return os; |
| 250 | } |
| 251 | |
| David Tolnay | 9ed15c6 | 2020-10-31 18:02:03 -0700 | [diff] [blame] | 252 | static_assert(std::is_trivially_copy_constructible<Str>::value, |
| 253 | "trivial Str(const Str &)"); |
| 254 | static_assert(std::is_trivially_copy_assignable<Str>::value, |
| 255 | "trivial operator=(const Str &)"); |
| 256 | static_assert(std::is_trivially_destructible<Str>::value, "trivial ~Str()"); |
| 257 | |
| David Tolnay | 4092191 | 2020-11-23 20:44:48 -0800 | [diff] [blame] | 258 | static_assert(std::is_trivially_copy_constructible<Slice<const uint8_t>>::value, |
| 259 | "trivial Slice(const Slice &)"); |
| 260 | static_assert(std::is_trivially_move_constructible<Slice<const uint8_t>>::value, |
| 261 | "trivial Slice(Slice &&)"); |
| 262 | static_assert(std::is_trivially_copy_assignable<Slice<const uint8_t>>::value, |
| 263 | "trivial Slice::operator=(const Slice &) for const slices"); |
| 264 | static_assert(std::is_trivially_move_assignable<Slice<const uint8_t>>::value, |
| 265 | "trivial Slice::operator=(Slice &&)"); |
| 266 | static_assert(std::is_trivially_destructible<Slice<const uint8_t>>::value, |
| 267 | "trivial ~Slice()"); |
| 268 | |
| David Tolnay | c5629f0 | 2020-11-23 18:32:46 -0800 | [diff] [blame] | 269 | static_assert(std::is_trivially_copy_constructible<Slice<uint8_t>>::value, |
| 270 | "trivial Slice(const Slice &)"); |
| 271 | static_assert(std::is_trivially_move_constructible<Slice<uint8_t>>::value, |
| 272 | "trivial Slice(Slice &&)"); |
| 273 | static_assert(!std::is_copy_assignable<Slice<uint8_t>>::value, |
| 274 | "delete Slice::operator=(const Slice &) for mut slices"); |
| 275 | static_assert(std::is_trivially_move_assignable<Slice<uint8_t>>::value, |
| 276 | "trivial Slice::operator=(Slice &&)"); |
| 277 | static_assert(std::is_trivially_destructible<Slice<uint8_t>>::value, |
| 278 | "trivial ~Slice()"); |
| 279 | |
| David Tolnay | 9578cf1 | 2020-11-25 14:36:46 -0800 | [diff] [blame] | 280 | static_assert(std::is_same<Vec<uint8_t>::const_iterator, |
| 281 | Vec<const uint8_t>::iterator>::value, |
| 282 | "Vec<T>::const_iterator == Vec<const T>::iterator"); |
| 283 | static_assert(std::is_same<Vec<const uint8_t>::const_iterator, |
| 284 | Vec<const uint8_t>::iterator>::value, |
| 285 | "Vec<const T>::const_iterator == Vec<const T>::iterator"); |
| 286 | static_assert( |
| 287 | !std::is_same<Vec<uint8_t>::const_iterator, Vec<uint8_t>::iterator>::value, |
| 288 | "Vec<T>::const_iterator != Vec<T>::iterator"); |
| 289 | |
| David Tolnay | 1e54817 | 2020-03-16 13:37:09 -0700 | [diff] [blame] | 290 | extern "C" { |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 291 | const char *cxxbridge1$error(const char *ptr, size_t len) { |
| David Tolnay | 1e54817 | 2020-03-16 13:37:09 -0700 | [diff] [blame] | 292 | char *copy = new char[len]; |
| David Tolnay | 504cf3c | 2020-10-31 16:08:04 -0700 | [diff] [blame] | 293 | std::strncpy(copy, ptr, len); |
| David Tolnay | 1e54817 | 2020-03-16 13:37:09 -0700 | [diff] [blame] | 294 | return copy; |
| 295 | } |
| 296 | } // extern "C" |
| 297 | |
| David Tolnay | d5712ee | 2020-10-31 17:10:00 -0700 | [diff] [blame] | 298 | Error::Error(const Error &other) |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 299 | : std::exception(other), msg(cxxbridge1$error(other.msg, other.len)), |
| David Tolnay | 23c2319 | 2020-10-31 17:11:48 -0700 | [diff] [blame] | 300 | len(other.len) {} |
| David Tolnay | 1e54817 | 2020-03-16 13:37:09 -0700 | [diff] [blame] | 301 | |
| David Tolnay | 23c2319 | 2020-10-31 17:11:48 -0700 | [diff] [blame] | 302 | Error::Error(Error &&other) noexcept |
| 303 | : std::exception(std::move(other)), msg(other.msg), len(other.len) { |
| David Tolnay | a0c9bc7 | 2020-10-31 14:37:14 -0700 | [diff] [blame] | 304 | other.msg = nullptr; |
| 305 | other.len = 0; |
| David Tolnay | 1e54817 | 2020-03-16 13:37:09 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| David Tolnay | a0c9bc7 | 2020-10-31 14:37:14 -0700 | [diff] [blame] | 308 | Error::~Error() noexcept { delete[] this->msg; } |
| David Tolnay | 1e54817 | 2020-03-16 13:37:09 -0700 | [diff] [blame] | 309 | |
| David Tolnay | 7c6ac71 | 2020-10-31 17:22:28 -0700 | [diff] [blame] | 310 | Error &Error::operator=(const Error &other) { |
| 311 | if (this != &other) { |
| 312 | std::exception::operator=(other); |
| 313 | delete[] this->msg; |
| 314 | this->msg = nullptr; |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 315 | this->msg = cxxbridge1$error(other.msg, other.len); |
| David Tolnay | 7c6ac71 | 2020-10-31 17:22:28 -0700 | [diff] [blame] | 316 | this->len = other.len; |
| 317 | } |
| 318 | return *this; |
| 319 | } |
| 320 | |
| David Tolnay | 1549106 | 2020-10-31 17:25:13 -0700 | [diff] [blame] | 321 | Error &Error::operator=(Error &&other) noexcept { |
| 322 | if (this != &other) { |
| 323 | std::exception::operator=(std::move(other)); |
| 324 | this->msg = other.msg; |
| 325 | this->len = other.len; |
| 326 | other.msg = nullptr; |
| 327 | other.len = 0; |
| 328 | } |
| 329 | return *this; |
| 330 | } |
| 331 | |
| David Tolnay | a0c9bc7 | 2020-10-31 14:37:14 -0700 | [diff] [blame] | 332 | const char *Error::what() const noexcept { return this->msg; } |
| David Tolnay | 1e54817 | 2020-03-16 13:37:09 -0700 | [diff] [blame] | 333 | |
| David Tolnay | 5b16340 | 2020-12-10 19:26:02 -0800 | [diff] [blame] | 334 | namespace { |
| 335 | template <typename T> |
| 336 | union MaybeUninit { |
| 337 | T value; |
| 338 | MaybeUninit() {} |
| 339 | ~MaybeUninit() {} |
| 340 | }; |
| 341 | } // namespace |
| 342 | |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 343 | } // namespace cxxbridge1 |
| David Tolnay | 750755e | 2020-03-01 13:04:08 -0800 | [diff] [blame] | 344 | } // namespace rust |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 345 | |
| 346 | extern "C" { |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 347 | void cxxbridge1$unique_ptr$std$string$null( |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 348 | std::unique_ptr<std::string> *ptr) noexcept { |
| 349 | new (ptr) std::unique_ptr<std::string>(); |
| 350 | } |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 351 | void cxxbridge1$unique_ptr$std$string$raw(std::unique_ptr<std::string> *ptr, |
| 352 | std::string *raw) noexcept { |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 353 | new (ptr) std::unique_ptr<std::string>(raw); |
| 354 | } |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 355 | const std::string *cxxbridge1$unique_ptr$std$string$get( |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 356 | const std::unique_ptr<std::string> &ptr) noexcept { |
| 357 | return ptr.get(); |
| 358 | } |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 359 | std::string *cxxbridge1$unique_ptr$std$string$release( |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 360 | std::unique_ptr<std::string> &ptr) noexcept { |
| 361 | return ptr.release(); |
| 362 | } |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 363 | void cxxbridge1$unique_ptr$std$string$drop( |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 364 | std::unique_ptr<std::string> *ptr) noexcept { |
| 365 | ptr->~unique_ptr(); |
| 366 | } |
| 367 | } // extern "C" |
| Myron Ahn | eba35cf | 2020-02-05 19:41:51 +0700 | [diff] [blame] | 368 | |
| David Tolnay | 06677b3 | 2020-11-23 18:05:45 -0800 | [diff] [blame] | 369 | namespace { |
| 370 | const size_t kMaxExpectedWordsInString = 8; |
| David Tolnay | bb3ff5d | 2020-11-15 19:45:11 -0800 | [diff] [blame] | 371 | static_assert(alignof(std::string) <= alignof(void *), |
| 372 | "unexpectedly large std::string alignment"); |
| David Tolnay | 06677b3 | 2020-11-23 18:05:45 -0800 | [diff] [blame] | 373 | static_assert(sizeof(std::string) <= kMaxExpectedWordsInString * sizeof(void *), |
| David Tolnay | bb3ff5d | 2020-11-15 19:45:11 -0800 | [diff] [blame] | 374 | "unexpectedly large std::string size"); |
| David Tolnay | c26de54 | 2020-11-23 18:18:19 -0800 | [diff] [blame] | 375 | } // namespace |
| David Tolnay | bb3ff5d | 2020-11-15 19:45:11 -0800 | [diff] [blame] | 376 | |
| David Tolnay | 37dd7e1 | 2020-04-25 12:51:59 -0700 | [diff] [blame] | 377 | #define STD_VECTOR_OPS(RUST_TYPE, CXX_TYPE) \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 378 | size_t cxxbridge1$std$vector$##RUST_TYPE##$size( \ |
| David Tolnay | 37dd7e1 | 2020-04-25 12:51:59 -0700 | [diff] [blame] | 379 | const std::vector<CXX_TYPE> &s) noexcept { \ |
| 380 | return s.size(); \ |
| 381 | } \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 382 | const CXX_TYPE *cxxbridge1$std$vector$##RUST_TYPE##$get_unchecked( \ |
| David Tolnay | 37dd7e1 | 2020-04-25 12:51:59 -0700 | [diff] [blame] | 383 | const std::vector<CXX_TYPE> &s, size_t pos) noexcept { \ |
| David Tolnay | 9626d08 | 2020-04-24 14:52:45 -0700 | [diff] [blame] | 384 | return &s[pos]; \ |
| David Tolnay | 37dd7e1 | 2020-04-25 12:51:59 -0700 | [diff] [blame] | 385 | } \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 386 | void cxxbridge1$unique_ptr$std$vector$##RUST_TYPE##$null( \ |
| David Tolnay | 996db1e | 2020-04-24 14:46:31 -0700 | [diff] [blame] | 387 | std::unique_ptr<std::vector<CXX_TYPE>> *ptr) noexcept { \ |
| 388 | new (ptr) std::unique_ptr<std::vector<CXX_TYPE>>(); \ |
| David Tolnay | 37dd7e1 | 2020-04-25 12:51:59 -0700 | [diff] [blame] | 389 | } \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 390 | void cxxbridge1$unique_ptr$std$vector$##RUST_TYPE##$raw( \ |
| David Tolnay | 996db1e | 2020-04-24 14:46:31 -0700 | [diff] [blame] | 391 | std::unique_ptr<std::vector<CXX_TYPE>> *ptr, \ |
| David Tolnay | 37dd7e1 | 2020-04-25 12:51:59 -0700 | [diff] [blame] | 392 | std::vector<CXX_TYPE> *raw) noexcept { \ |
| David Tolnay | 996db1e | 2020-04-24 14:46:31 -0700 | [diff] [blame] | 393 | new (ptr) std::unique_ptr<std::vector<CXX_TYPE>>(raw); \ |
| David Tolnay | 37dd7e1 | 2020-04-25 12:51:59 -0700 | [diff] [blame] | 394 | } \ |
| David Tolnay | 4e7e7c4 | 2020-04-24 14:48:07 -0700 | [diff] [blame] | 395 | const std::vector<CXX_TYPE> \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 396 | *cxxbridge1$unique_ptr$std$vector$##RUST_TYPE##$get( \ |
| David Tolnay | 996db1e | 2020-04-24 14:46:31 -0700 | [diff] [blame] | 397 | const std::unique_ptr<std::vector<CXX_TYPE>> &ptr) noexcept { \ |
| David Tolnay | 37dd7e1 | 2020-04-25 12:51:59 -0700 | [diff] [blame] | 398 | return ptr.get(); \ |
| 399 | } \ |
| David Tolnay | 4e7e7c4 | 2020-04-24 14:48:07 -0700 | [diff] [blame] | 400 | std::vector<CXX_TYPE> \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 401 | *cxxbridge1$unique_ptr$std$vector$##RUST_TYPE##$release( \ |
| David Tolnay | 996db1e | 2020-04-24 14:46:31 -0700 | [diff] [blame] | 402 | std::unique_ptr<std::vector<CXX_TYPE>> &ptr) noexcept { \ |
| David Tolnay | 37dd7e1 | 2020-04-25 12:51:59 -0700 | [diff] [blame] | 403 | return ptr.release(); \ |
| 404 | } \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 405 | void cxxbridge1$unique_ptr$std$vector$##RUST_TYPE##$drop( \ |
| David Tolnay | 996db1e | 2020-04-24 14:46:31 -0700 | [diff] [blame] | 406 | std::unique_ptr<std::vector<CXX_TYPE>> *ptr) noexcept { \ |
| David Tolnay | 37dd7e1 | 2020-04-25 12:51:59 -0700 | [diff] [blame] | 407 | ptr->~unique_ptr(); \ |
| David Tolnay | 4e7e7c4 | 2020-04-24 14:48:07 -0700 | [diff] [blame] | 408 | } |
| Myron Ahn | eba35cf | 2020-02-05 19:41:51 +0700 | [diff] [blame] | 409 | |
| David Tolnay | 6787be6 | 2020-04-25 11:01:02 -0700 | [diff] [blame] | 410 | #define RUST_VEC_EXTERNS(RUST_TYPE, CXX_TYPE) \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 411 | void cxxbridge1$rust_vec$##RUST_TYPE##$new( \ |
| David Tolnay | f97c2d5 | 2020-04-25 16:37:48 -0700 | [diff] [blame] | 412 | rust::Vec<CXX_TYPE> *ptr) noexcept; \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 413 | void cxxbridge1$rust_vec$##RUST_TYPE##$drop( \ |
| David Tolnay | 6787be6 | 2020-04-25 11:01:02 -0700 | [diff] [blame] | 414 | rust::Vec<CXX_TYPE> *ptr) noexcept; \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 415 | size_t cxxbridge1$rust_vec$##RUST_TYPE##$len( \ |
| David Tolnay | 6787be6 | 2020-04-25 11:01:02 -0700 | [diff] [blame] | 416 | const rust::Vec<CXX_TYPE> *ptr) noexcept; \ |
| David Tolnay | dc62d71 | 2020-12-11 13:51:53 -0800 | [diff] [blame^] | 417 | size_t cxxbridge1$rust_vec$##RUST_TYPE##$capacity( \ |
| 418 | const rust::Vec<CXX_TYPE> *ptr) noexcept; \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 419 | const CXX_TYPE *cxxbridge1$rust_vec$##RUST_TYPE##$data( \ |
| David Tolnay | 6787be6 | 2020-04-25 11:01:02 -0700 | [diff] [blame] | 420 | const rust::Vec<CXX_TYPE> *ptr) noexcept; \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 421 | void cxxbridge1$rust_vec$##RUST_TYPE##$reserve_total( \ |
| David Tolnay | fb6b73c | 2020-11-10 14:32:16 -0800 | [diff] [blame] | 422 | rust::Vec<CXX_TYPE> *ptr, size_t cap) noexcept; \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 423 | void cxxbridge1$rust_vec$##RUST_TYPE##$set_len(rust::Vec<CXX_TYPE> *ptr, \ |
| 424 | size_t len) noexcept; \ |
| 425 | size_t cxxbridge1$rust_vec$##RUST_TYPE##$stride() noexcept; |
| David Tolnay | 6787be6 | 2020-04-25 11:01:02 -0700 | [diff] [blame] | 426 | |
| 427 | #define RUST_VEC_OPS(RUST_TYPE, CXX_TYPE) \ |
| 428 | template <> \ |
| David Tolnay | 1768d8f | 2020-04-25 18:15:11 -0700 | [diff] [blame] | 429 | Vec<CXX_TYPE>::Vec() noexcept { \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 430 | cxxbridge1$rust_vec$##RUST_TYPE##$new(this); \ |
| David Tolnay | f97c2d5 | 2020-04-25 16:37:48 -0700 | [diff] [blame] | 431 | } \ |
| 432 | template <> \ |
| David Tolnay | 1768d8f | 2020-04-25 18:15:11 -0700 | [diff] [blame] | 433 | void Vec<CXX_TYPE>::drop() noexcept { \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 434 | return cxxbridge1$rust_vec$##RUST_TYPE##$drop(this); \ |
| David Tolnay | 6787be6 | 2020-04-25 11:01:02 -0700 | [diff] [blame] | 435 | } \ |
| 436 | template <> \ |
| David Tolnay | 1768d8f | 2020-04-25 18:15:11 -0700 | [diff] [blame] | 437 | size_t Vec<CXX_TYPE>::size() const noexcept { \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 438 | return cxxbridge1$rust_vec$##RUST_TYPE##$len(this); \ |
| David Tolnay | 6787be6 | 2020-04-25 11:01:02 -0700 | [diff] [blame] | 439 | } \ |
| 440 | template <> \ |
| David Tolnay | dc62d71 | 2020-12-11 13:51:53 -0800 | [diff] [blame^] | 441 | size_t Vec<CXX_TYPE>::capacity() const noexcept { \ |
| 442 | return cxxbridge1$rust_vec$##RUST_TYPE##$capacity(this); \ |
| 443 | } \ |
| 444 | template <> \ |
| David Tolnay | 1768d8f | 2020-04-25 18:15:11 -0700 | [diff] [blame] | 445 | const CXX_TYPE *Vec<CXX_TYPE>::data() const noexcept { \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 446 | return cxxbridge1$rust_vec$##RUST_TYPE##$data(this); \ |
| David Tolnay | 6787be6 | 2020-04-25 11:01:02 -0700 | [diff] [blame] | 447 | } \ |
| 448 | template <> \ |
| David Tolnay | fb6b73c | 2020-11-10 14:32:16 -0800 | [diff] [blame] | 449 | void Vec<CXX_TYPE>::reserve_total(size_t cap) noexcept { \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 450 | cxxbridge1$rust_vec$##RUST_TYPE##$reserve_total(this, cap); \ |
| David Tolnay | fb6b73c | 2020-11-10 14:32:16 -0800 | [diff] [blame] | 451 | } \ |
| 452 | template <> \ |
| 453 | void Vec<CXX_TYPE>::set_len(size_t len) noexcept { \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 454 | cxxbridge1$rust_vec$##RUST_TYPE##$set_len(this, len); \ |
| David Tolnay | fb6b73c | 2020-11-10 14:32:16 -0800 | [diff] [blame] | 455 | } \ |
| 456 | template <> \ |
| David Tolnay | 1768d8f | 2020-04-25 18:15:11 -0700 | [diff] [blame] | 457 | size_t Vec<CXX_TYPE>::stride() noexcept { \ |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 458 | return cxxbridge1$rust_vec$##RUST_TYPE##$stride(); \ |
| David Tolnay | 6787be6 | 2020-04-25 11:01:02 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| David Tolnay | 5b16340 | 2020-12-10 19:26:02 -0800 | [diff] [blame] | 461 | #define SHARED_PTR_OPS(RUST_TYPE, CXX_TYPE) \ |
| 462 | static_assert(sizeof(std::shared_ptr<CXX_TYPE>) == 2 * sizeof(void *), ""); \ |
| 463 | static_assert(alignof(std::shared_ptr<CXX_TYPE>) == alignof(void *), ""); \ |
| 464 | void cxxbridge1$std$shared_ptr$##RUST_TYPE##$null( \ |
| 465 | std::shared_ptr<CXX_TYPE> *ptr) noexcept { \ |
| 466 | new (ptr) std::shared_ptr<CXX_TYPE>(); \ |
| 467 | } \ |
| 468 | CXX_TYPE *cxxbridge1$std$shared_ptr$##RUST_TYPE##$uninit( \ |
| 469 | std::shared_ptr<CXX_TYPE> *ptr) noexcept { \ |
| 470 | CXX_TYPE *uninit = \ |
| 471 | reinterpret_cast<CXX_TYPE *>(new rust::MaybeUninit<CXX_TYPE>); \ |
| 472 | new (ptr) std::shared_ptr<CXX_TYPE>(uninit); \ |
| 473 | return uninit; \ |
| 474 | } \ |
| 475 | void cxxbridge1$std$shared_ptr$##RUST_TYPE##$clone( \ |
| 476 | const std::shared_ptr<CXX_TYPE> &self, \ |
| 477 | std::shared_ptr<CXX_TYPE> *ptr) noexcept { \ |
| 478 | new (ptr) std::shared_ptr<CXX_TYPE>(self); \ |
| 479 | } \ |
| 480 | const CXX_TYPE *cxxbridge1$std$shared_ptr$##RUST_TYPE##$get( \ |
| 481 | const std::shared_ptr<CXX_TYPE> &self) noexcept { \ |
| 482 | return self.get(); \ |
| 483 | } \ |
| 484 | void cxxbridge1$std$shared_ptr$##RUST_TYPE##$drop( \ |
| 485 | const std::shared_ptr<CXX_TYPE> *self) noexcept { \ |
| 486 | self->~shared_ptr(); \ |
| 487 | } |
| 488 | |
| David Tolnay | 6787be6 | 2020-04-25 11:01:02 -0700 | [diff] [blame] | 489 | // Usize and isize are the same type as one of the below. |
| David Tolnay | f336b3b | 2020-04-30 08:45:54 -0700 | [diff] [blame] | 490 | #define FOR_EACH_NUMERIC(MACRO) \ |
| David Tolnay | 6787be6 | 2020-04-25 11:01:02 -0700 | [diff] [blame] | 491 | MACRO(u8, uint8_t) \ |
| 492 | MACRO(u16, uint16_t) \ |
| 493 | MACRO(u32, uint32_t) \ |
| 494 | MACRO(u64, uint64_t) \ |
| 495 | MACRO(i8, int8_t) \ |
| 496 | MACRO(i16, int16_t) \ |
| 497 | MACRO(i32, int32_t) \ |
| 498 | MACRO(i64, int64_t) \ |
| 499 | MACRO(f32, float) \ |
| 500 | MACRO(f64, double) |
| 501 | |
| David Tolnay | f336b3b | 2020-04-30 08:45:54 -0700 | [diff] [blame] | 502 | #define FOR_EACH_STD_VECTOR(MACRO) \ |
| 503 | FOR_EACH_NUMERIC(MACRO) \ |
| David Tolnay | 6787be6 | 2020-04-25 11:01:02 -0700 | [diff] [blame] | 504 | MACRO(usize, size_t) \ |
| David Tolnay | 47e239d | 2020-08-28 00:32:04 -0700 | [diff] [blame] | 505 | MACRO(isize, rust::isize) \ |
| 506 | MACRO(string, std::string) |
| David Tolnay | 6787be6 | 2020-04-25 11:01:02 -0700 | [diff] [blame] | 507 | |
| David Tolnay | f336b3b | 2020-04-30 08:45:54 -0700 | [diff] [blame] | 508 | #define FOR_EACH_RUST_VEC(MACRO) \ |
| 509 | FOR_EACH_NUMERIC(MACRO) \ |
| David Tolnay | 33f56ad | 2020-08-27 17:06:35 -0700 | [diff] [blame] | 510 | MACRO(bool, bool) \ |
| David Tolnay | 93e71d0 | 2020-11-25 20:16:52 -0800 | [diff] [blame] | 511 | MACRO(char, char) \ |
| David Tolnay | 33f56ad | 2020-08-27 17:06:35 -0700 | [diff] [blame] | 512 | MACRO(string, rust::String) |
| David Tolnay | f336b3b | 2020-04-30 08:45:54 -0700 | [diff] [blame] | 513 | |
| David Tolnay | 5b16340 | 2020-12-10 19:26:02 -0800 | [diff] [blame] | 514 | #define FOR_EACH_SHARED_PTR(MACRO) \ |
| 515 | FOR_EACH_NUMERIC(MACRO) \ |
| 516 | MACRO(usize, size_t) \ |
| 517 | MACRO(isize, rust::isize) \ |
| 518 | MACRO(string, std::string) |
| 519 | |
| David Tolnay | 4e7e7c4 | 2020-04-24 14:48:07 -0700 | [diff] [blame] | 520 | extern "C" { |
| David Tolnay | f336b3b | 2020-04-30 08:45:54 -0700 | [diff] [blame] | 521 | FOR_EACH_STD_VECTOR(STD_VECTOR_OPS) |
| 522 | FOR_EACH_RUST_VEC(RUST_VEC_EXTERNS) |
| David Tolnay | 5b16340 | 2020-12-10 19:26:02 -0800 | [diff] [blame] | 523 | FOR_EACH_SHARED_PTR(SHARED_PTR_OPS) |
| David Tolnay | 4e7e7c4 | 2020-04-24 14:48:07 -0700 | [diff] [blame] | 524 | } // extern "C" |
| David Tolnay | 6787be6 | 2020-04-25 11:01:02 -0700 | [diff] [blame] | 525 | |
| David Tolnay | 1768d8f | 2020-04-25 18:15:11 -0700 | [diff] [blame] | 526 | namespace rust { |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 527 | inline namespace cxxbridge1 { |
| David Tolnay | f336b3b | 2020-04-30 08:45:54 -0700 | [diff] [blame] | 528 | FOR_EACH_RUST_VEC(RUST_VEC_OPS) |
| David Tolnay | 0f0162f | 2020-11-16 23:43:37 -0800 | [diff] [blame] | 529 | } // namespace cxxbridge1 |
| David Tolnay | 1768d8f | 2020-04-25 18:15:11 -0700 | [diff] [blame] | 530 | } // namespace rust |