liveBook · Manning

Allowlist

As explained in Refactoring to Rust

A whitelist is a selection rule that restricts generated bindings to explicitly matching declarations.

An allowlist restricts generated bindings to declarations that match explicit rules. In an NGINX FFI, bindgen initially describes more than 51,000 lines, including the entire C standard library; filtering reduces unnecessary output and compile-time cost. section 4.3.2

Filter declarations by prefix

Add regular-expression rules such as whitelist_type("ngx_.*"), whitelist_function("ngx_.*"), and whitelist_var("ngx_.*"). Rerunning generation produces about 30,000 lines containing declarations whose names begin with ngx_. Explicitly allowing each required declaration is possible but deferred here. section 4.3.2

How Refactoring to Rust covers it

How deep it goes
Explains prefix-based filtering and its size reduction, but defers individually allowing every required declaration.
Examples
Demonstrates ngx_ type, function, and variable filters for NGINX declarations.
What it assumes
Assumes a bindgen build script, parsed C headers, and familiarity with NGINX declaration prefixes.
What you can do after
Apply bindgen filters to generate a smaller set of NGINX Rust bindings.
How it connects
Connects allowlists with bindgen, regular expressions, FFI, and Cargo build scripts.

Also explained in

Compare how 2 books explain allowlist →

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.