Begin to introduce Rust-style move for C++ objects
diff --git a/include/cxxbridge.h b/include/cxxbridge.h
index 1701f4d..1ac3133 100644
--- a/include/cxxbridge.h
+++ b/include/cxxbridge.h
@@ -8,6 +8,8 @@
namespace rust {
inline namespace cxxbridge01 {
+struct unsafe_bitcopy_t;
+
class String final {
public:
String() noexcept;
@@ -28,6 +30,9 @@
size_t size() const noexcept;
size_t length() const noexcept;
+ // Internal API only intended for the cxxbridge code generator.
+ String(unsafe_bitcopy_t, const String &) noexcept;
+
private:
// Size and alignment statically verified by rust_string.rs.
std::array<uintptr_t, 3> repr;
@@ -144,5 +149,10 @@
using str = Str;
template <class T> using box = Box<T>;
+struct unsafe_bitcopy_t {
+ explicit unsafe_bitcopy_t() = default;
+};
+constexpr unsafe_bitcopy_t unsafe_bitcopy{};
+
} // namespace cxxbridge01
} // namespace rust
diff --git a/src/cxxbridge.cc b/src/cxxbridge.cc
index c58b7c5..b44204d 100644
--- a/src/cxxbridge.cc
+++ b/src/cxxbridge.cc
@@ -87,6 +87,9 @@
size_t String::length() const noexcept { return cxxbridge01$string$len(this); }
+String::String(unsafe_bitcopy_t, const String &bits) noexcept
+ : repr(bits.repr) {}
+
std::ostream &operator<<(std::ostream &os, const String &s) {
os.write(s.data(), s.size());
return os;