mirror of
https://github.com/topjohnwu/cxx.git
synced 2024-11-27 13:50:24 +00:00
Rename C++ RustString to String
This commit is contained in:
parent
d944446b98
commit
5608216979
@ -298,7 +298,7 @@ of functions.
|
||||
|
||||
<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>
|
||||
|
@ -401,7 +401,7 @@ fn write_type(out: &mut OutFile, ty: &Type) {
|
||||
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) => {
|
||||
|
@ -9,16 +9,16 @@ namespace cxxbridge = cxxbridge01;
|
||||
|
||||
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 @@ private:
|
||||
};
|
||||
#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
|
||||
|
@ -14,16 +14,16 @@ size_t cxxbridge01$cxx_string$length(const std::string &s) noexcept {
|
||||
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 @@ bool cxxbridge01$rust_str$valid(const char *ptr, size_t len) noexcept;
|
||||
|
||||
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 @@ RustString &RustString::operator=(const RustString &other) noexcept {
|
||||
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 @@ RustString &RustString::operator=(RustString &&other) noexcept {
|
||||
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;
|
||||
}
|
||||
|
@ -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>
|
||||
|
@ -24,7 +24,7 @@ cxxbridge::RustStr c_return_str(const Shared &shared) {
|
||||
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_str(cxxbridge::RustStr s) {
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ extern "C" const char *cxx_run_test() noexcept {
|
||||
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")));
|
||||
|
||||
|
@ -23,7 +23,7 @@ cxxbridge::RustBox<R> c_return_box();
|
||||
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_unique_ptr(std::unique_ptr<C> c);
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user