liveBook · Manning

Type signature

As explained in Refactoring to Rust

A function signature specifies a function's parameter types, return type, and the semantic roles of those values.

A function signature specifies every parameter type, the return type, and the semantic role of each value. In a C FFI, matching the existing signature lets C call the Rust function. section 3.2

Matching a C function

The C declaration `int solve(char *line, int *solution)` becomes `fn solve(line: *const c_char, solution: *mut c_int) -> c_int` in Rust. The Rust signature additionally shows that `solution` may be modified while `line` is not. section 3.2

How Refactoring to Rust covers it

How deep it goes
Explains parameter types, return types, semantic roles, and mutability implications, stopping short of broader type-system theory.
Examples
Compares the C and Rust declarations for the calculator's solve function.
What it assumes
Assumes familiarity with a C function declaration while teaching Rust pointer types and mutability signals through the translation.
What you can do after
Apply it via matching Rust parameter and return types to an existing C function interface.
How it connects
Connects function signatures with C FFI, Rust pointers, mutability, and the libc crate.

Also explained in

Compare how 8 books explain type signature →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Refactoring to Rust. The section links point to the parts of the book it draws on.