Restore swapping Str and Slice in member function form only
diff --git a/book/src/binding/slice.md b/book/src/binding/slice.md
index fe1691e..803277b 100644
--- a/book/src/binding/slice.md
+++ b/book/src/binding/slice.md
@@ -40,6 +40,8 @@
class iterator;
iterator begin() const noexcept;
iterator end() const noexcept;
+
+ void swap(Slice &) noexcept;
};
#
# template <typename T>
diff --git a/book/src/binding/str.md b/book/src/binding/str.md
index 999727c..a4820aa 100644
--- a/book/src/binding/str.md
+++ b/book/src/binding/str.md
@@ -44,6 +44,8 @@
bool operator<=(const Str &) const noexcept;
bool operator>(const Str &) const noexcept;
bool operator>=(const Str &) const noexcept;
+
+ void swap(Str &) noexcept;
};
std::ostream &operator<<(std::ostream &, const Str &);
diff --git a/include/cxx.h b/include/cxx.h
index ee4de41..03f719f 100644
--- a/include/cxx.h
+++ b/include/cxx.h
@@ -125,6 +125,8 @@
bool operator>(const Str &) const noexcept;
bool operator>=(const Str &) const noexcept;
+ void swap(Str &) noexcept;
+
private:
std::array<std::uintptr_t, 2> repr;
};
@@ -175,6 +177,8 @@
iterator begin() const noexcept;
iterator end() const noexcept;
+ void swap(Slice &) noexcept;
+
private:
// Not necessarily ABI compatible with &[T]. Codegen will translate to
// cxx::rust_slice::RustSlice which matches this layout.
@@ -666,6 +670,11 @@
it.pos = static_cast<char *>(it.pos) + it.stride * this->len;
return it;
}
+
+template <typename T>
+void Slice<T>::swap(Slice &rhs) noexcept {
+ std::swap(*this, rhs);
+}
#endif // CXXBRIDGE1_RUST_SLICE
#ifndef CXXBRIDGE1_RUST_BOX
diff --git a/src/cxx.cc b/src/cxx.cc
index 5d38966..605845e 100644
--- a/src/cxx.cc
+++ b/src/cxx.cc
@@ -267,6 +267,8 @@
bool Str::operator>=(const Str &rhs) const noexcept { return rhs <= *this; }
+void Str::swap(Str &rhs) noexcept { std::swap(*this, rhs); }
+
std::ostream &operator<<(std::ostream &os, const Str &s) {
os.write(s.data(), s.size());
return os;