mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-04-28 17:55:41 +02:00
The new Chromium class likes — like me! — to use dashes in the writing! However, I believe it should use an em-dash instead of the hyphen. Luckily this is easy: we have enabled “typographic quotes” in `mdbook`, which also handles the conversion of `---` to `—` in the generated HTML. So I normalized the single existing em-dash to a triple-dash to make it more consistent (and hopefully make it easier for translators to consistently enter these characters).
28 lines
1.1 KiB
Markdown
28 lines
1.1 KiB
Markdown
# Interoperability with C++
|
|
|
|
The Rust community offers multiple options for C++/Rust interop, with new tools
|
|
being developed all the time. At the moment, Chromium uses a tool called "cxx".
|
|
|
|
You describe your whole language boundary in an interface definition language
|
|
(which looks a lot like Rust) and then cxx tools generate declarations for
|
|
functions and types in both Rust and C++.
|
|
|
|
<img src="../android/interoperability/cpp/overview.svg" alt="Overview diagram of cxx, showing that the same interface definition is used to create both C++ and Rust side code which then communicate via a lowest common denominator C API">
|
|
|
|
See the [CXX tutorial][1] for a full example of using this.
|
|
|
|
|
|
[1]: https://cxx.rs/tutorial.html
|
|
[2]: https://cxx.rs/bindings.html
|
|
|
|
|
|
<details>
|
|
|
|
Talk through the diagram. Explain that behind the scenes, this is doing
|
|
just the same as you previously did --- but by programmatically ensuring that
|
|
the C++ and Rust sides match, cxx can ensure there aren't obvious errors
|
|
with object lifetimes, string lengths, etc. It reduces lots of fiddly
|
|
boilerplate and the resulting code feels more "natural".
|
|
|
|
</details>
|