liveBook · Manning

Foreign function interface

Also called FFI

A foreign function interface is a mechanism that enables code in one programming language to call or interoperate with code or data from another language through compatible conventions.

How 4 Manning books explain it

Embedded Software with Rust

A mechanism for declaring and calling functions across programming-language boundaries using compatible binary conventions.

How it is used
Connects Rust firmware to C libraries, vendor HALs, drivers, startup code, and RTOS kernels.
How deep it goes
Explains extern declarations, ABI and scalar matching, and safe wrappers; names arrays, C strings, and callbacks without detailing them.
Examples
Demonstrates a C function call, C-to-Rust scalar mappings, a Rust export, and checked wrappers for addition and hardware writes.
What you can do after
Apply Rust FFI to declare C functions, match target-compatible scalar types, export Rust symbols, and isolate unsafe calls behind checked wrappers.

Read how Embedded Software with Rust explains foreign function interface →

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 →

Systems Programming with Zig

A foreign function interface is an interface that allows code written in one programming language to call or interoperate with code written in another.

How it is used
Use it to let a PHP web application call a Zig-backed recipe-book library instead of implementing backend logic in PHP.
How deep it goes
Defines FFI through a PHP–Zig project and identifies C ABI compatibility, without detailing call mechanics.
Examples
Uses a recipe-book backend whose API creates, retrieves, lists, deletes, saves, and loads recipes.
What you can do after
Build a cross-language library by exposing Zig code through the C ABI for a PHP application.

Read how Systems Programming with Zig explains foreign function interface →

Also covered in

What to know first

Related concepts

Questions about foreign function interface

What is foreign function interface?

A foreign function interface is a mechanism that enables code in one programming language to call or interoperate with code or data from another language through compatible conventions.

Which Manning books explain foreign function interface?

Embedded Software with Rust, Code Like a Pro in Rust, Refactoring to Rust and Systems Programming with Zig.

What should I know before learning foreign function interface?

Manning books that teach foreign function interface usually introduce C++, calling convention, memory allocation and string first.

What is foreign function interface also called?

Foreign function interface is also called FFI.

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.