Add Str(const String &) noexcept constructor
diff --git a/book/src/binding/str.md b/book/src/binding/str.md
index b0a99b4..93e9750 100644
--- a/book/src/binding/str.md
+++ b/book/src/binding/str.md
@@ -15,6 +15,7 @@
public:
Str() noexcept;
Str(const Str &) noexcept;
+ Str(const String &) noexcept;
// Throws std::invalid_argument if not utf-8.
Str(const std::string &);
diff --git a/gen/src/builtin.rs b/gen/src/builtin.rs
index 8741e2d..5182e01 100644
--- a/gen/src/builtin.rs
+++ b/gen/src/builtin.rs
@@ -115,6 +115,11 @@
out.end_block(Block::AnonymousNamespace);
}
+ if builtin.rust_str && !builtin.rust_string {
+ out.next_section();
+ writeln!(out, "class String;");
+ }
+
ifndef::write(out, builtin.rust_string, "CXXBRIDGE1_RUST_STRING");
ifndef::write(out, builtin.rust_str, "CXXBRIDGE1_RUST_STR");
ifndef::write(out, builtin.rust_slice, "CXXBRIDGE1_RUST_SLICE");
diff --git a/include/cxx.h b/include/cxx.h
index fe45121..e40876d 100644
--- a/include/cxx.h
+++ b/include/cxx.h
@@ -73,6 +73,7 @@
class Str final {
public:
Str() noexcept;
+ Str(const String &) noexcept;
Str(const std::string &);
Str(const char *);
Str(const char *, size_t);
diff --git a/src/cxx.cc b/src/cxx.cc
index ef5db8f..c9e2151 100644
--- a/src/cxx.cc
+++ b/src/cxx.cc
@@ -150,6 +150,8 @@
Str::Str() noexcept : ptr(reinterpret_cast<const char *>(1)), len(0) {}
+Str::Str(const String &s) noexcept : ptr(s.data()), len(s.length()) {}
+
static void initStr(const char *ptr, size_t len) {
if (!cxxbridge1$str$valid(ptr, len)) {
panic<std::invalid_argument>("data for rust::Str is not utf-8");