1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-28 01:49:05 +02:00
comprehensive-rust/src/chromium/interoperability-with-cpp.md
Martin Geisler aebb0bc856
Replace hyphens (-) with em-dashes () (#1500)
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).
2023-11-28 19:41:09 +01:00

1.1 KiB

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++.

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 for a full example of using this.

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".