Com C++
O crate CXX possibilita a interoperabilidade segura entre Rust e C++.
A abordagem geral Ă© assim:
Veja o tutorial CXX para um exemplo completo de como usĂĄ-lo.
-
At this point, the instructor should switch to the CXX tutorial.
-
Walk the students through the tutorial step by step.
-
Highlight how CXX presents a clean interface without unsafe code in both languages.
-
Show the correspondence between Rust and C++ types:
-
Explain how a Rust
Stringcannot map to a C++std::string(the latter does not uphold the UTF-8 invariant). Show that despite being different types,rust::Stringin C++ can be easily constructed from a C++std::string, making it very ergonomic to use. -
Explain that a Rust function returning
Result<T, E>becomes a function which throws aEexception in C++ (and vice versa).
-