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.
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
- Writing for Developers: Blogs that get read
- Rust in Action: Systems programming concepts and techniques
- Learn Rust in a Month of Lunches
What to know first
- C++C++ is a statically typed, general-purpose programming language that supports procedural, object-oriented, generic, and low-level systems programming.
- calling conventionA calling convention is a set of binary-interface rules specifying how functions receive arguments, return values, preserve state, and manage calls.
- memory allocationMemory allocation is the process of reserving or assigning computer memory to hold program data or objects.
- stringA string is a programming-language value representing textual data as an ordered sequence of characters or encoded units.
Related concepts
- C++uses · C++ is a statically typed, general-purpose programming language that supports procedural, object-oriented, generic, and low-level systems programming.
- Rustuses · Rust is a statically typed systems programming language designed for performance, concurrency, and memory safety without requiring garbage collection.
- trust boundaryequivalent to · A trust boundary is a separation across which assumptions about the trust, authority, control, or security of components, data, or actions change.
- Zigused by · Zig is a general-purpose systems programming language emphasizing simplicity, explicit control over resources, predictable performance, and interoperability with C.
- unsafe Rustuses · Unsafe Rust is Rust code that permits operations whose safety conditions the compiler cannot fully verify and that therefore require the programmer to uphold the relevant invariants.
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.



