3 ms·
> In otherwords, what carbon can do that Rust can't do, is take a C++ class with a `foo` method and call that method. Or create a class with a `foo` method and
by formerly_proven 4y ago
> In otherwords, what carbon can do that Rust can't do, is take a C++ class with a `foo` method and call that method. Or create a class with a `foo` method and call that method from C++. Probably one of the biggest hurdles to get over in C++ interopt. Most don't do that, instead you'd make a C function binding and struct and move data/invoke functions through that.
https://cxx.rs https://cxx.rs
- IshKebab 4y agocxx is great but it isn't anything close to what cogman10 is describing. It actually can't ever be, because C++ has move constructors and Rust deliberately doesn't, so you can't for example return `std::string` from a Rust function by value.
- deleted 4y ago[deleted]
- hlopko 4y agoIt's currently unclear if Rust can interop with C++ with high fidelity. For example https://docs.rs/moveit/latest/moveit/ https://docs.rs/moveit/latest/moveit/ and https://github.com/google/crubit/blob/main/rs_bindings_from_cc/support/ctor.rs https://github.com/google/crubit/blob/main/rs_bindings_from_... provide functionality to use non-trivially relocatable C++ types from Rust.
- IshKebab 4y agoBit hard to follow but as far as I can tell those are pinning the C++ types and wrapping them in some other object that allows a move constructor to be called on them to move them to some other pinned location. It still doesn't let you natively move them, and if you have to wrap them in something you may as well just wrap them in `Box<>` and not move them, which is what cxx does. I guess maybe it makes a difference for passing things into existing C++ interfaces? Anyway it looks insanely complicated.
- deleted 4y ago[deleted]
- ridiculous_fish 4y agoI tried cxx and walked away somewhat disappointed. One problem is that it's hard to understand the code. The whole thing is one giant proc macro, which is by itself tricky to run and debug. Also it uses techniques like implementing Deref to simulate inheritance which makes it even more confusing. The main problem is the difficulty in extending it. Support for std::string and std::vector are "baked in" in a way that does not generalize. I tried to add support for std::wstring and it is quite non-trivial. Because it is a proc macro it's also tricky to integrate into a build system. To me it seems like Cxx is "purpose built" which is fine. But after working with it, I longed for a Python script that just populates a template string or something.