Back to Comprehensive Rust

Language Interop

src/unsafe-deep-dive/ffi/language-interop.md

latest1.3 KB
Original Source
<!-- Copyright 2026 Google LLC SPDX-License-Identifier: CC-BY-4.0 -->

Language Interop

Ideal scenario:

bob
╭────────────╮                                          ╭────────────╮
│            │                                          │            │
│            │ <--------------------------------------> │            │
│            │                                          │            │
╰────────────╯                                          ╰────────────╯
     Rust                                                    "C++"
<details>

This section of the course covers interacting with Rust and external languages via its foreign-function interface (FFI), with a special focus on interoperability with C++.

Ideally, users of Rust and the external language (in this case C++) could call each others’ methods directly.

This ideal scenario is very difficult to achieve:

Different languages have different semantics and mapping between them implies trade-offs Neither Rust nor C++ offer ABI stability1, making it difficult to build from a stable foundation

</details>

Footnotes

  1. Some C++ compiler vendors provide support for ABI stability within their toolchain.