cxx icon indicating copy to clipboard operation
cxx copied to clipboard

CxxVector::new / CxxVector::with_capacity

Open smessmer opened this issue 4 years ago • 2 comments

Thanks for adding CxxVector::push/pop in https://github.com/dtolnay/cxx/issues/778. To remove the other most common kind of manual binding work when working with CxxVector, a CxxVector::new and a CxxVector::with_capacity function would be great. A (for me) common pattern is to call a C++ function from rust and passing it a CxxVector of C++ objects (say CxxVector<SharedPtr>). With CxxVector::new/with_capacity, I could create the CxxVector and add all the SharedPtr to it entirely on the Rust side without having to go through manual ffi bindings.

smessmer avatar Apr 23 '21 22:04 smessmer

Hm yeah this one is a little odd omission. I have lots of C++ APIs that accept std::vector of various types, and it's unclear how to create those from Rust in the current model.

RReverser avatar Dec 18 '22 20:12 RReverser

Ah... wait, I can't even create bindings for APIs that accept std::vector<CustomType>. In that case creation is a smaller problem.

RReverser avatar Dec 19 '22 17:12 RReverser