aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--book/src/binding/slice.md2
-rw-r--r--book/src/binding/str.md2
-rw-r--r--include/cxx.h9
-rw-r--r--src/cxx.cc2
4 files changed, 15 insertions, 0 deletions
diff --git a/book/src/binding/slice.md b/book/src/binding/slice.md
index fe1691e3..803277ba 100644
--- a/book/src/binding/slice.md
+++ b/book/src/binding/slice.md
@@ -40,6 +40,8 @@ public:
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 999727c0..a4820aaf 100644
--- a/book/src/binding/str.md
+++ b/book/src/binding/str.md
@@ -44,6 +44,8 @@ public:
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 ee4de419..03f719fd 100644
--- a/include/cxx.h
+++ b/include/cxx.h
@@ -125,6 +125,8 @@ public:
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 @@ public:
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 @@ typename Slice<T>::iterator Slice<T>::end() const noexcept {
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 5d38966c..605845e1 100644
--- a/src/cxx.cc
+++ b/src/cxx.cc
@@ -267,6 +267,8 @@ bool Str::operator>(const Str &rhs) const noexcept { return rhs < *this; }
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;