mirror of
https://github.com/topjohnwu/cxx.git
synced 2025-02-23 09:30:45 +00:00
Rename C++ RustBox to Box
This commit is contained in:
parent
09dbe75a5d
commit
324437a263
@ -301,7 +301,7 @@ of functions.
|
||||
<tr><td>String</td><td>cxxbridge::String</td><td></td></tr>
|
||||
<tr><td>&str</td><td>cxxbridge::Str</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>
|
||||
<tr><td>Box<T></td><td>cxxbridge::Box<T></td><td><sup><i>cannot hold opaque C++ type</i></sup></td></tr>
|
||||
<tr><td><a href="https://docs.rs/cxx/0.1/cxx/struct.UniquePtr.html">UniquePtr<T></a></td><td>std::unique_ptr<T></td><td><sup><i>cannot hold opaque Rust type</i></sup></td></tr>
|
||||
<tr><td></td><td></td><td></td></tr>
|
||||
</table>
|
||||
|
26
gen/write.rs
26
gen/write.rs
@ -405,7 +405,7 @@ fn write_type(out: &mut OutFile, ty: &Type) {
|
||||
None => write!(out, "{}", ident),
|
||||
},
|
||||
Type::RustBox(ty) => {
|
||||
write!(out, "::cxxbridge::RustBox<");
|
||||
write!(out, "::cxxbridge::Box<");
|
||||
write_type(out, &ty.inner);
|
||||
write!(out, ">");
|
||||
}
|
||||
@ -482,27 +482,27 @@ fn write_rust_box_extern(out: &mut OutFile, ident: &Ident) {
|
||||
writeln!(out, "#define CXXBRIDGE01_RUST_BOX_{}", instance);
|
||||
writeln!(
|
||||
out,
|
||||
"void cxxbridge01$rust_box${}$uninit(::cxxbridge::RustBox<{}> *ptr) noexcept;",
|
||||
"void cxxbridge01$rust_box${}$uninit(::cxxbridge::Box<{}> *ptr) noexcept;",
|
||||
instance, inner,
|
||||
);
|
||||
writeln!(
|
||||
out,
|
||||
"void cxxbridge01$rust_box${}$set_raw(::cxxbridge::RustBox<{}> *ptr, {} *raw) noexcept;",
|
||||
"void cxxbridge01$rust_box${}$set_raw(::cxxbridge::Box<{}> *ptr, {} *raw) noexcept;",
|
||||
instance, inner, inner
|
||||
);
|
||||
writeln!(
|
||||
out,
|
||||
"void cxxbridge01$rust_box${}$drop(::cxxbridge::RustBox<{}> *ptr) noexcept;",
|
||||
"void cxxbridge01$rust_box${}$drop(::cxxbridge::Box<{}> *ptr) noexcept;",
|
||||
instance, inner,
|
||||
);
|
||||
writeln!(
|
||||
out,
|
||||
"const {} *cxxbridge01$rust_box${}$deref(const ::cxxbridge::RustBox<{}> *ptr) noexcept;",
|
||||
"const {} *cxxbridge01$rust_box${}$deref(const ::cxxbridge::Box<{}> *ptr) noexcept;",
|
||||
inner, instance, inner,
|
||||
);
|
||||
writeln!(
|
||||
out,
|
||||
"{} *cxxbridge01$rust_box${}$deref_mut(::cxxbridge::RustBox<{}> *ptr) noexcept;",
|
||||
"{} *cxxbridge01$rust_box${}$deref_mut(::cxxbridge::Box<{}> *ptr) noexcept;",
|
||||
inner, instance, inner,
|
||||
);
|
||||
writeln!(out, "#endif // CXXBRIDGE01_RUST_BOX_{}", instance);
|
||||
@ -518,7 +518,7 @@ fn write_rust_box_impl(out: &mut OutFile, ident: &Ident) {
|
||||
let instance = inner.replace("::", "$");
|
||||
|
||||
writeln!(out, "template <>");
|
||||
writeln!(out, "void RustBox<{}>::uninit() noexcept {{", inner);
|
||||
writeln!(out, "void Box<{}>::uninit() noexcept {{", inner);
|
||||
writeln!(
|
||||
out,
|
||||
" return cxxbridge01$rust_box${}$uninit(this);",
|
||||
@ -529,7 +529,7 @@ fn write_rust_box_impl(out: &mut OutFile, ident: &Ident) {
|
||||
writeln!(out, "template <>");
|
||||
writeln!(
|
||||
out,
|
||||
"void RustBox<{}>::set_raw({} *raw) noexcept {{",
|
||||
"void Box<{}>::set_raw({} *raw) noexcept {{",
|
||||
inner, inner,
|
||||
);
|
||||
writeln!(
|
||||
@ -540,7 +540,7 @@ fn write_rust_box_impl(out: &mut OutFile, ident: &Ident) {
|
||||
writeln!(out, "}}");
|
||||
|
||||
writeln!(out, "template <>");
|
||||
writeln!(out, "void RustBox<{}>::drop() noexcept {{", inner);
|
||||
writeln!(out, "void Box<{}>::drop() noexcept {{", inner);
|
||||
writeln!(
|
||||
out,
|
||||
" return cxxbridge01$rust_box${}$drop(this);",
|
||||
@ -551,7 +551,7 @@ fn write_rust_box_impl(out: &mut OutFile, ident: &Ident) {
|
||||
writeln!(out, "template <>");
|
||||
writeln!(
|
||||
out,
|
||||
"const {} *RustBox<{}>::deref() const noexcept {{",
|
||||
"const {} *Box<{}>::deref() const noexcept {{",
|
||||
inner, inner,
|
||||
);
|
||||
writeln!(
|
||||
@ -562,11 +562,7 @@ fn write_rust_box_impl(out: &mut OutFile, ident: &Ident) {
|
||||
writeln!(out, "}}");
|
||||
|
||||
writeln!(out, "template <>");
|
||||
writeln!(
|
||||
out,
|
||||
"{} *RustBox<{}>::deref_mut() noexcept {{",
|
||||
inner, inner,
|
||||
);
|
||||
writeln!(out, "{} *Box<{}>::deref_mut() noexcept {{", inner, inner);
|
||||
writeln!(
|
||||
out,
|
||||
" return cxxbridge01$rust_box${}$deref_mut(this);",
|
||||
|
@ -63,15 +63,15 @@ private:
|
||||
|
||||
#ifndef CXXBRIDGE01_RUST_BOX
|
||||
#define CXXBRIDGE01_RUST_BOX
|
||||
template <typename T> class RustBox final {
|
||||
template <typename T> class Box final {
|
||||
public:
|
||||
RustBox(const RustBox &other) : RustBox(*other) {}
|
||||
RustBox(RustBox &&other) noexcept : repr(other.repr) { other.repr = 0; }
|
||||
RustBox(const T &val) {
|
||||
Box(const Box &other) : Box(*other) {}
|
||||
Box(Box &&other) noexcept : repr(other.repr) { other.repr = 0; }
|
||||
Box(const T &val) {
|
||||
this->uninit();
|
||||
::new (this->deref_mut()) T(val);
|
||||
}
|
||||
RustBox &operator=(const RustBox &other) {
|
||||
Box &operator=(const Box &other) {
|
||||
if (this != &other) {
|
||||
if (this->repr) {
|
||||
**this = *other;
|
||||
@ -82,7 +82,7 @@ public:
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
RustBox &operator=(RustBox &&other) noexcept {
|
||||
Box &operator=(Box &&other) noexcept {
|
||||
if (this->repr) {
|
||||
this->drop();
|
||||
}
|
||||
@ -90,7 +90,7 @@ public:
|
||||
other.repr = 0;
|
||||
return *this;
|
||||
}
|
||||
~RustBox() noexcept {
|
||||
~Box() noexcept {
|
||||
if (this->repr) {
|
||||
this->drop();
|
||||
}
|
||||
@ -103,8 +103,8 @@ public:
|
||||
|
||||
// Important: requires that `raw` came from an into_raw call. Do not pass a
|
||||
// pointer from `new` or any other source.
|
||||
static RustBox from_raw(T *raw) noexcept {
|
||||
RustBox box;
|
||||
static Box from_raw(T *raw) noexcept {
|
||||
Box box;
|
||||
box.set_raw(raw);
|
||||
return box;
|
||||
}
|
||||
@ -116,7 +116,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
RustBox() noexcept {}
|
||||
Box() noexcept {}
|
||||
void uninit() noexcept;
|
||||
void set_raw(T *) noexcept;
|
||||
T *get_raw() noexcept;
|
||||
|
@ -305,7 +305,7 @@
|
||||
//! <tr><td>String</td><td>cxxbridge::String</td><td></td></tr>
|
||||
//! <tr><td>&str</td><td>cxxbridge::Str</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>
|
||||
//! <tr><td>Box<T></td><td>cxxbridge::Box<T></td><td><sup><i>cannot hold opaque C++ type</i></sup></td></tr>
|
||||
//! <tr><td><a href="https://docs.rs/cxx/0.1/cxx/struct.UniquePtr.html">UniquePtr<T></a></td><td>std::unique_ptr<T></td><td><sup><i>cannot hold opaque Rust type</i></sup></td></tr>
|
||||
//! <tr><td></td><td></td><td></td></tr>
|
||||
//! </table>
|
||||
|
@ -42,7 +42,7 @@ void c_take_shared(Shared shared) {
|
||||
}
|
||||
}
|
||||
|
||||
void c_take_box(cxxbridge::RustBox<R> r) {
|
||||
void c_take_box(cxxbridge::Box<R> r) {
|
||||
(void)r;
|
||||
cxx_test_suite_set_correct();
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ private:
|
||||
|
||||
size_t c_return_primitive();
|
||||
Shared c_return_shared();
|
||||
cxxbridge::RustBox<R> c_return_box();
|
||||
cxxbridge::Box<R> c_return_box();
|
||||
std::unique_ptr<C> c_return_unique_ptr();
|
||||
const size_t &c_return_ref(const Shared &shared);
|
||||
cxxbridge::Str c_return_str(const Shared &shared);
|
||||
@ -28,7 +28,7 @@ std::unique_ptr<std::string> c_return_unique_ptr_string();
|
||||
|
||||
void c_take_primitive(size_t n);
|
||||
void c_take_shared(Shared shared);
|
||||
void c_take_box(cxxbridge::RustBox<R> r);
|
||||
void c_take_box(cxxbridge::Box<R> r);
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user