Rename C++ RustString to String
diff --git a/README.md b/README.md
index e7eaa3a..406518b 100644
--- a/README.md
+++ b/README.md
@@ -298,7 +298,7 @@
<table>
<tr><th>name in Rust</th><th>name in C++</th><th>restrictions</th></tr>
-<tr><td>String</td><td>cxxbridge::RustString</td><td></td></tr>
+<tr><td>String</td><td>cxxbridge::String</td><td></td></tr>
<tr><td>&str</td><td>cxxbridge::RustStr</td><td></td></tr>
<tr><td><a href="https://docs.rs/cxx/0.1/cxx/struct.CxxString.html">CxxString</a></td><td>std::string</td><td><sup><i>cannot be passed by value</i></sup></td></tr>
<tr><td>Box<T></td><td>cxxbridge::RustBox<T></td><td><sup><i>cannot hold opaque C++ type</i></sup></td></tr>
diff --git a/gen/write.rs b/gen/write.rs
index 9034a16..d55d4ac 100644
--- a/gen/write.rs
+++ b/gen/write.rs
@@ -401,7 +401,7 @@
Some(I64) => write!(out, "int64_t"),
Some(Isize) => write!(out, "ssize_t"),
Some(CxxString) => write!(out, "::std::string"),
- Some(RustString) => write!(out, "::cxxbridge::RustString"),
+ Some(RustString) => write!(out, "::cxxbridge::String"),
None => write!(out, "{}", ident),
},
Type::RustBox(ty) => {
diff --git a/include/cxxbridge.h b/include/cxxbridge.h
index 8061c28..395ec18 100644
--- a/include/cxxbridge.h
+++ b/include/cxxbridge.h
@@ -9,16 +9,16 @@
namespace cxxbridge01 {
-class RustString final {
+class String final {
public:
- RustString() noexcept;
- RustString(const RustString &other) noexcept;
- RustString(RustString &&other) noexcept;
- RustString(const char *s);
- RustString(const std::string &s);
- RustString &operator=(const RustString &other) noexcept;
- RustString &operator=(RustString &&other) noexcept;
- ~RustString() noexcept;
+ String() noexcept;
+ String(const String &other) noexcept;
+ String(String &&other) noexcept;
+ String(const char *s);
+ String(const std::string &s);
+ String &operator=(const String &other) noexcept;
+ String &operator=(String &&other) noexcept;
+ ~String() noexcept;
operator std::string() const;
// Note: no null terminator.
@@ -127,7 +127,7 @@
};
#endif // CXXBRIDGE01_RUST_BOX
-std::ostream &operator<<(std::ostream &os, const RustString &s);
+std::ostream &operator<<(std::ostream &os, const String &s);
std::ostream &operator<<(std::ostream &os, const RustStr &s);
} // namespace cxxbridge01
diff --git a/src/cxxbridge.cc b/src/cxxbridge.cc
index a502d20..1134c6b 100644
--- a/src/cxxbridge.cc
+++ b/src/cxxbridge.cc
@@ -14,16 +14,16 @@
return s.length();
}
-// RustString
-void cxxbridge01$rust_string$new(cxxbridge::RustString *self) noexcept;
-void cxxbridge01$rust_string$clone(cxxbridge::RustString *self,
- const cxxbridge::RustString &other) noexcept;
-bool cxxbridge01$rust_string$from(cxxbridge::RustString *self, const char *ptr,
+// cxxbridge::String
+void cxxbridge01$rust_string$new(cxxbridge::String *self) noexcept;
+void cxxbridge01$rust_string$clone(cxxbridge::String *self,
+ const cxxbridge::String &other) noexcept;
+bool cxxbridge01$rust_string$from(cxxbridge::String *self, const char *ptr,
size_t len) noexcept;
-void cxxbridge01$rust_string$drop(cxxbridge::RustString *self) noexcept;
+void cxxbridge01$rust_string$drop(cxxbridge::String *self) noexcept;
const char *
-cxxbridge01$rust_string$ptr(const cxxbridge::RustString *self) noexcept;
-size_t cxxbridge01$rust_string$len(const cxxbridge::RustString *self) noexcept;
+cxxbridge01$rust_string$ptr(const cxxbridge::String *self) noexcept;
+size_t cxxbridge01$rust_string$len(const cxxbridge::String *self) noexcept;
// RustStr
bool cxxbridge01$rust_str$valid(const char *ptr, size_t len) noexcept;
@@ -31,39 +31,39 @@
namespace cxxbridge01 {
-RustString::RustString() noexcept { cxxbridge01$rust_string$new(this); }
+String::String() noexcept { cxxbridge01$rust_string$new(this); }
-RustString::RustString(const RustString &other) noexcept {
+String::String(const String &other) noexcept {
cxxbridge01$rust_string$clone(this, other);
}
-RustString::RustString(RustString &&other) noexcept {
+String::String(String &&other) noexcept {
this->repr = other.repr;
cxxbridge01$rust_string$new(&other);
}
-RustString::RustString(const char *s) {
+String::String(const char *s) {
auto len = strlen(s);
if (!cxxbridge01$rust_string$from(this, s, len)) {
- throw std::invalid_argument("data for RustString is not utf-8");
+ throw std::invalid_argument("data for cxxbridge::String is not utf-8");
}
}
-RustString::RustString(const std::string &s) {
+String::String(const std::string &s) {
auto ptr = s.data();
auto len = s.length();
if (!cxxbridge01$rust_string$from(this, ptr, len)) {
- throw std::invalid_argument("data for RustString is not utf-8");
+ throw std::invalid_argument("data for cxxbridge::String is not utf-8");
}
}
-RustString::~RustString() noexcept { cxxbridge01$rust_string$drop(this); }
+String::~String() noexcept { cxxbridge01$rust_string$drop(this); }
-RustString::operator std::string() const {
+String::operator std::string() const {
return std::string(this->data(), this->size());
}
-RustString &RustString::operator=(const RustString &other) noexcept {
+String &String::operator=(const String &other) noexcept {
if (this != &other) {
cxxbridge01$rust_string$drop(this);
cxxbridge01$rust_string$clone(this, other);
@@ -71,7 +71,7 @@
return *this;
}
-RustString &RustString::operator=(RustString &&other) noexcept {
+String &String::operator=(String &&other) noexcept {
if (this != &other) {
cxxbridge01$rust_string$drop(this);
this->repr = other.repr;
@@ -80,19 +80,19 @@
return *this;
}
-const char *RustString::data() const noexcept {
+const char *String::data() const noexcept {
return cxxbridge01$rust_string$ptr(this);
}
-size_t RustString::size() const noexcept {
+size_t String::size() const noexcept {
return cxxbridge01$rust_string$len(this);
}
-size_t RustString::length() const noexcept {
+size_t String::length() const noexcept {
return cxxbridge01$rust_string$len(this);
}
-std::ostream &operator<<(std::ostream &os, const RustString &s) {
+std::ostream &operator<<(std::ostream &os, const String &s) {
os.write(s.data(), s.size());
return os;
}
diff --git a/src/lib.rs b/src/lib.rs
index 4c0f3c9..69f9447 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -302,7 +302,7 @@
//!
//! <table>
//! <tr><th>name in Rust</th><th>name in C++</th><th>restrictions</th></tr>
-//! <tr><td>String</td><td>cxxbridge::RustString</td><td></td></tr>
+//! <tr><td>String</td><td>cxxbridge::String</td><td></td></tr>
//! <tr><td>&str</td><td>cxxbridge::RustStr</td><td></td></tr>
//! <tr><td><a href="https://docs.rs/cxx/0.1/cxx/struct.CxxString.html">CxxString</a></td><td>std::string</td><td><sup><i>cannot be passed by value</i></sup></td></tr>
//! <tr><td>Box<T></td><td>cxxbridge::RustBox<T></td><td><sup><i>cannot hold opaque C++ type</i></sup></td></tr>
diff --git a/tests/ffi/tests.cc b/tests/ffi/tests.cc
index d27df41..60f6141 100644
--- a/tests/ffi/tests.cc
+++ b/tests/ffi/tests.cc
@@ -24,7 +24,7 @@
return "2020";
}
-cxxbridge::RustString c_return_rust_string() { return "2020"; }
+cxxbridge::String c_return_rust_string() { return "2020"; }
std::unique_ptr<std::string> c_return_unique_ptr_string() {
return std::unique_ptr<std::string>(new std::string("2020"));
@@ -67,7 +67,7 @@
}
}
-void c_take_rust_string(cxxbridge::RustString s) {
+void c_take_rust_string(cxxbridge::String s) {
if (std::string(s) == "2020") {
cxx_test_suite_set_correct();
}
@@ -100,7 +100,7 @@
r_take_unique_ptr(std::unique_ptr<C>(new C{2020}));
r_take_ref_c(C{2020});
r_take_str(cxxbridge::RustStr("2020"));
- // TODO r_take_rust_string(cxxbridge::RustString("2020"));
+ // TODO r_take_rust_string(cxxbridge::String("2020"));
r_take_unique_ptr_string(
std::unique_ptr<std::string>(new std::string("2020")));
diff --git a/tests/ffi/tests.h b/tests/ffi/tests.h
index 87aac67..fa4e3c8 100644
--- a/tests/ffi/tests.h
+++ b/tests/ffi/tests.h
@@ -23,7 +23,7 @@
std::unique_ptr<C> c_return_unique_ptr();
const size_t &c_return_ref(const Shared &shared);
cxxbridge::RustStr c_return_str(const Shared &shared);
-cxxbridge::RustString c_return_rust_string();
+cxxbridge::String c_return_rust_string();
std::unique_ptr<std::string> c_return_unique_ptr_string();
void c_take_primitive(size_t n);
@@ -33,7 +33,7 @@
void c_take_ref_r(const R &r);
void c_take_ref_c(const C &c);
void c_take_str(cxxbridge::RustStr s);
-void c_take_rust_string(cxxbridge::RustString s);
+void c_take_rust_string(cxxbridge::String s);
void c_take_unique_ptr_string(std::unique_ptr<std::string> s);
} // namespace tests