@@ -39,7 +39,12 @@ std::size_t cxxbridge1$string$len(const rust::String *self) noexcept;
39
39
void cxxbridge1$string$reserve_total(rust::String *self, size_t cap) noexcept ;
40
40
41
41
// rust::Str
42
- bool cxxbridge1$str$valid(const char *ptr, std::size_t len) noexcept ;
42
+ void cxxbridge1$str$new (rust::Str *self) noexcept ;
43
+ void cxxbridge1$str$ref(rust::Str *self, const rust::String *string) noexcept ;
44
+ bool cxxbridge1$str$from(rust::Str *self, const char *ptr,
45
+ std::size_t len) noexcept ;
46
+ const char *cxxbridge1$str$ptr(const rust::Str *self) noexcept ;
47
+ std::size_t cxxbridge1$str$len(const rust::Str *self) noexcept ;
43
48
} // extern "C"
44
49
45
50
namespace rust {
@@ -185,46 +190,52 @@ std::ostream &operator<<(std::ostream &os, const String &s) {
185
190
return os;
186
191
}
187
192
188
- Str::Str () noexcept : ptr( reinterpret_cast < const char *>( 1 )), len( 0 ) { }
193
+ Str::Str () noexcept { cxxbridge1$str$ new ( this ); }
189
194
190
- Str::Str (const String &s) noexcept : ptr(s.data()), len(s.length()) { }
195
+ Str::Str (const String &s) noexcept { cxxbridge1$str$ ref ( this , &s); }
191
196
192
- static void initStr (const char *ptr, std::size_t len) {
193
- if (!cxxbridge1$str$valid ( ptr, len)) {
197
+ static void initStr (Str *self, const char *ptr, std::size_t len) {
198
+ if (!cxxbridge1$str$from (self, ptr, len)) {
194
199
panic<std::invalid_argument>(" data for rust::Str is not utf-8" );
195
200
}
196
201
}
197
202
198
- Str::Str (const std::string &s) : ptr(s.data()), len(s.length()) {
199
- initStr (this ->ptr , this ->len );
200
- }
203
+ Str::Str (const std::string &s) { initStr (this , s.data (), s.length ()); }
201
204
202
- Str::Str (const char *s) : ptr(s), len(std::strlen(s)) {
205
+ Str::Str (const char *s) {
203
206
assert (s != nullptr );
204
- initStr (this -> ptr , this -> len );
207
+ initStr (this , s, std::strlen (s) );
205
208
}
206
209
207
- Str::Str (const char *s, std::size_t len)
208
- : ptr(s == nullptr && len == 0 ? reinterpret_cast <const char *>(1 ) : s),
209
- len (len) {
210
+ Str::Str (const char *s, std::size_t len) {
210
211
assert (s != nullptr || len == 0 );
211
- initStr (this ->ptr , this ->len );
212
+ initStr (this ,
213
+ s == nullptr && len == 0 ? reinterpret_cast <const char *>(1 ) : s,
214
+ len);
212
215
}
213
216
214
217
Str::operator std::string () const {
215
218
return std::string (this ->data (), this ->size ());
216
219
}
217
220
221
+ const char *Str::data () const noexcept { return cxxbridge1$str$ptr (this ); }
222
+
223
+ std::size_t Str::size () const noexcept { return cxxbridge1$str$len (this ); }
224
+
225
+ std::size_t Str::length () const noexcept { return this ->size (); }
226
+
218
227
Str::const_iterator Str::begin () const noexcept { return this ->cbegin (); }
219
228
220
229
Str::const_iterator Str::end () const noexcept { return this ->cend (); }
221
230
222
- Str::const_iterator Str::cbegin () const noexcept { return this ->ptr ; }
231
+ Str::const_iterator Str::cbegin () const noexcept { return this ->data () ; }
223
232
224
- Str::const_iterator Str::cend () const noexcept { return this ->ptr + this ->len ; }
233
+ Str::const_iterator Str::cend () const noexcept {
234
+ return this ->data () + this ->size ();
235
+ }
225
236
226
237
bool Str::operator ==(const Str &rhs) const noexcept {
227
- return this ->len == rhs.len &&
238
+ return this ->size () == rhs.size () &&
228
239
std::equal (this ->begin (), this ->end (), rhs.begin ());
229
240
}
230
241
0 commit comments