liveBook · Manning

Foreign function interface

A foreign function interface is a mechanism that enables code in one programming language to call functions or access data provided by another language through compatible conventions.

How 2 Manning books explain it

Code Like a Pro in Rust

A foreign function interface is a mechanism that allows code in one programming language to call functions or use data types defined in another language.

How it is used
Connects Rust applications to existing C libraries and accelerates other languages with native Rust components.
How deep it goes
Demonstrates declarations, linking, unsafe calls, wrappers, struct layout, and binding generation without exhaustively covering complex C APIs.
Examples
Uses zlib compression, decompression, gzip-file reading, C headers, and bindings for Python, Ruby, Elixir, Erlang, and Node.js.
What you can do after
Build it from scratch by declaring C interfaces, linking native libraries, mapping compatible types, and wrapping unsafe calls.

Read how Code Like a Pro in Rust explains foreign function interface →

Refactoring to Rust

A foreign function interface based on the C calling and binary interface that enables programs in different languages to call C-compatible functions and exchange compatible data.

How it is used
Supports incremental refactoring by embedding Rust components in existing applications and allowing other languages to call them.
How deep it goes
Explains calling conventions, value exchange, memory sharing, wrappers, linking, strings, and unsafe operations, while deferring detailed techniques.
Examples
Uses Rust libraries called from Python-like applications, Rust embedded in C, cdylib linking, CStr conversion, and raw-pointer wrappers.
What you can do after
Build it from scratch by exposing Rust functions to C-compatible callers and containing unsafe boundary code in wrappers.

Read how Refactoring to Rust explains foreign function interface →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.