Rename C++ RustBox to Box
diff --git a/README.md b/README.md
index 551bc7c..27c0c83 100644
--- a/README.md
+++ b/README.md
@@ -301,7 +301,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>
diff --git a/gen/write.rs b/gen/write.rs
index 063a674..31eee36 100644
--- a/gen/write.rs
+++ b/gen/write.rs
@@ -405,7 +405,7 @@
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 @@
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 @@
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 @@
writeln!(out, "template <>");
writeln!(
out,
- "void RustBox<{}>::set_raw({} *raw) noexcept {{",
+ "void Box<{}>::set_raw({} *raw) noexcept {{",
inner, inner,
);
writeln!(
@@ -540,7 +540,7 @@
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 @@
writeln!(out, "template <>");
writeln!(
out,
- "const {} *RustBox<{}>::deref() const noexcept {{",
+ "const {} *Box<{}>::deref() const noexcept {{",
inner, inner,
);
writeln!(
@@ -562,11 +562,7 @@
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);",
diff --git a/include/cxxbridge.h b/include/cxxbridge.h
index fb00bb4..2ff3d20 100644
--- a/include/cxxbridge.h
+++ b/include/cxxbridge.h
@@ -63,15 +63,15 @@
#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 @@
}
return *this;
}
- RustBox &operator=(RustBox &&other) noexcept {
+ Box &operator=(Box &&other) noexcept {
if (this->repr) {
this->drop();
}
@@ -90,7 +90,7 @@
other.repr = 0;
return *this;
}
- ~RustBox() noexcept {
+ ~Box() noexcept {
if (this->repr) {
this->drop();
}
@@ -103,8 +103,8 @@
// 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 @@
}
private:
- RustBox() noexcept {}
+ Box() noexcept {}
void uninit() noexcept;
void set_raw(T *) noexcept;
T *get_raw() noexcept;
diff --git a/src/lib.rs b/src/lib.rs
index 2f21166..abf7321 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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>
diff --git a/tests/ffi/tests.cc b/tests/ffi/tests.cc
index a5305ef..5800f29 100644
--- a/tests/ffi/tests.cc
+++ b/tests/ffi/tests.cc
@@ -42,7 +42,7 @@
}
}
-void c_take_box(cxxbridge::RustBox<R> r) {
+void c_take_box(cxxbridge::Box<R> r) {
(void)r;
cxx_test_suite_set_correct();
}
diff --git a/tests/ffi/tests.h b/tests/ffi/tests.h
index fe3d966..3600eb6 100644
--- a/tests/ffi/tests.h
+++ b/tests/ffi/tests.h
@@ -19,7 +19,7 @@
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 @@
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);