cxx icon indicating copy to clipboard operation
cxx copied to clipboard

Add let_cxx_vector to construct CxxVector on stack

Open compiler-errors opened this issue 3 years ago • 1 comments

Implement let_cxx_vector macro, very similarly to let_cxx_string, to enable constructing a CxxVector<T> on the stack.

Helps with calling methods that take std::vector as an out variable.

compiler-errors avatar Aug 04 '21 22:08 compiler-errors

@hanusek's #961 reminded me that this PR was open.

@dtolnay: is this change something you consider reasonable, and if so, can I get a review on it sometime? If it's not worthwhile or is fundamentally broken in some way, I'll just close it.

compiler-errors avatar Nov 22 '21 22:11 compiler-errors

Hi @dtolnay, pinging you here, as evaluating this one for going in would be an incredible help to a lot of workflows (at least for me).

PR looks clean, has tests, could do with a rebase on top of recent master but no merge conflicts.

What would it take for this to be taken forward?

NlightNFotis avatar Dec 12 '22 14:12 NlightNFotis

Hi @dtolnay, many thanks for a very prompt response.

In light of this decision, what would you suggest is the best way to construct a CxxVector<CxxString> and pass it to the C++ side?

Would I be better off just creating the Rust equivalents and translate them into the C++ APIs in the .cpp file?

Thanks again,

NlightNFotis avatar Dec 12 '22 15:12 NlightNFotis

You can do that or you can obtain an empty UniquePtr<CxxVector<CxxString>> from C++ to put elements into. Or, via a callback, obtain a Pin<&mut CxxVector<CxxString>> for the Rust code to fill.

dtolnay avatar Dec 12 '22 15:12 dtolnay