cxx
cxx copied to clipboard
Issue 87: Bindings for Option
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
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.
I also ran into the issue of
Option<Pin<&mut T>>
versusPin<Option<&mut T>>
and also ofOption<Option<&T>>
in that PR (Pin<Pin<&mut T>>
is allowed today and normalizes to justPin<&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.
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.
Is this pr going anywhere? I am quite interested in this feature.
@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
Any progress? This feature would be pretty big... what's blocking it?
is anyone doing this?