aboutsummaryrefslogtreecommitdiff
path: root/src/cxx.cc
diff options
context:
space:
mode:
authorNikhil Benesch <nikhil.benesch@gmail.com>2021-12-26 15:18:50 -0500
committerNikhil Benesch <nikhil.benesch@gmail.com>2021-12-26 15:18:50 -0500
commite3918b5422a182e8c36e080284147cfcccc4f6cf (patch)
treec8622a66274d96e858f73fb9c57502d52dd52975 /src/cxx.cc
parentd662b6cbd4c3274308df48ad6ac89251500baf3c (diff)
downloadcxx-e3918b5422a182e8c36e080284147cfcccc4f6cf.tar.gz
Add Vec<T>::truncate to C++ API
Based on the model of #951, which added `Vec<T>::clear`. The `truncate` method is the more general form of clear. (If we wanted to, we could delete the binding for `clear` and implement `clear` as a call to `truncate(0)` on the C++ side, but seemed worth leaving in in case the Rust `clear` implementation one day gets smarter.)
Diffstat (limited to 'src/cxx.cc')
-rw-r--r--src/cxx.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/cxx.cc b/src/cxx.cc
index 4bdbd583..7fffa834 100644
--- a/src/cxx.cc
+++ b/src/cxx.cc
@@ -569,6 +569,8 @@ static_assert(sizeof(std::string) <= kMaxExpectedWordsInString * sizeof(void *),
rust::Vec<CXX_TYPE> *ptr, std::size_t new_cap) noexcept; \
void cxxbridge1$rust_vec$##RUST_TYPE##$set_len(rust::Vec<CXX_TYPE> *ptr, \
std::size_t len) noexcept; \
+ void cxxbridge1$rust_vec$##RUST_TYPE##$truncate(rust::Vec<CXX_TYPE> *ptr, \
+ std::size_t len) noexcept; \
void cxxbridge1$rust_vec$##RUST_TYPE##$clear( \
rust::Vec<CXX_TYPE> *ptr) noexcept;
@@ -602,6 +604,10 @@ static_assert(sizeof(std::string) <= kMaxExpectedWordsInString * sizeof(void *),
cxxbridge1$rust_vec$##RUST_TYPE##$set_len(this, len); \
} \
template <> \
+ void Vec<CXX_TYPE>::truncate(std::size_t len) { \
+ cxxbridge1$rust_vec$##RUST_TYPE##$truncate(this, len); \
+ } \
+ template <> \
void Vec<CXX_TYPE>::clear() { \
cxxbridge1$rust_vec$##RUST_TYPE##$clear(this); \
}