cxx icon indicating copy to clipboard operation
cxx copied to clipboard

Issue 87: Bindings for Option

Open kuecks opened this issue 3 years ago • 7 comments

Added bindings to rust's std::option::Option, and C++'s std::optional::optional. Still a WIP but this is able to compile and run a simple example

kuecks avatar Jul 06 '21 21:07 kuecks

I just want to note that this (deliberately) conflicts with #868, in which I would like to have Option<&T>Rust translate to T const*C++ on the C++ side, rather than ::rust::Option<T const*>C++ as implemented here. This is specifically for binding to existing C++ APIs that accept T* as either a valid pointer or nullptr.

I also ran into the issue of Option<Pin<&mut T>> versus Pin<Option<&mut T>> and also of Option<Option<&T>> in that PR (Pin<Pin<&mut T>> is allowed today and normalizes to just Pin<&mut T>); so make sure that you don't have the same issue here. I don't think you do, since I modeled Option as part of the pointer type (like Pin) and you've modeled Option as a new kind of type (like Box), but it's worth double checking that nesting works properly.

CAD97 avatar Aug 03 '21 21:08 CAD97

I also ran into the issue of Option<Pin<&mut T>> versus Pin<Option<&mut T>> and also of Option<Option<&T>> in that PR (Pin<Pin<&mut T>> is allowed today and normalizes to just Pin<&mut T>); so make sure that you don't have the same issue here.

Thanks for mentioning Pin, I wasn't handling it at all and needed to add special case for it.

kuecks avatar Aug 24 '21 05:08 kuecks

Notes: all the changes under demo/ will be reverted, that's just my playground. The code feels quire repetitive and nasty, but I can't figure out any better way, there's just so many subtly different cases :(. Also please let me know if you want me to break it up into multiple commits somehow for reviewability, this is quite massive.

kuecks avatar Aug 24 '21 05:08 kuecks

Is this pr going anywhere? I am quite interested in this feature.

djpiper28 avatar May 01 '22 15:05 djpiper28

@djpiper28 yes I am still interested in pushing this through, I think dtolnay is (understandably) just quite busy unfortunately. I may explore alternative implementations, specifically reference_wrapper, in the meantime

kuecks avatar May 04 '22 17:05 kuecks

Any progress? This feature would be pretty big... what's blocking it?

VirxEC avatar Dec 09 '22 21:12 VirxEC

is anyone doing this?

xdray avatar Mar 22 '23 14:03 xdray