Strategies of interop
Sharing data structures and symbols directly is very difficult:
FFI through the C ABI is much more feasible:
Other strategies:
- Distributed system (RPC)
- Custom ABI (i.e. WebAssembly Interface Types)
High-fidelity interop
The ideal scenario is currently experimental.
Two projects exploring this are crubit and Zngur. The first provides glue code on each side for enabling compatible types to work seamlessly across domains. The second relies on dynamic dispatch and imports C++ objects into Rust as trait objects.
Low-fidelity interop work through a C API
The typical strategy for interop is to use the C language as the interface. C is a lossy codec. This strategy typically results in complicated code on both sides.
Other strategies are less viable in a zero cost environment.
Distributed systems impose runtime costs.
They incur significant overhead as calling a method in a foreign library incurs a round trip of serialization/transport/deserialization. Generally speaking, a transparent RPC is not a good idea. There’s network in the middle.
Custom ABI, such as wasm require a runtime or significant implementation cost.