diff options
author | Nikhil Benesch <nikhil.benesch@gmail.com> | 2021-12-26 15:18:50 -0500 |
---|---|---|
committer | Nikhil Benesch <nikhil.benesch@gmail.com> | 2021-12-26 15:18:50 -0500 |
commit | e3918b5422a182e8c36e080284147cfcccc4f6cf (patch) | |
tree | c8622a66274d96e858f73fb9c57502d52dd52975 /src/cxx.cc | |
parent | d662b6cbd4c3274308df48ad6ac89251500baf3c (diff) | |
download | cxx-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.cc | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -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); \ } |