expression
Wrap generated declarations behind a safe API
Keep generated declarations private so application callers use reviewed wrappers. This wrapper accepts all u16 inputs because the specific C implementation has no pointer arguments and doubles within the u32 range. Generated bindings are not a proof of ABI compatibility; headers, compiler target and native binary must agree. Expected lab stdout (not executed): 42 Common mistake: Exposing arbitrary generated unsafe functions as safe without reviewing each contract. This is part of a multi-file lab, not a standalone playground snippet.
Formal Syntax & Structure
rust syntaxrust
include!(concat!(env!("OUT_DIR"), "/bindings.rs"))Working Example
Example Snippetrust
mod raw { #![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] include!(concat!(env!("OUT_DIR"), "/bindings.rs"));}fn scale(input: u16) -> u32 { // SAFETY: reviewed C implementation accepts all uint16_t values, returns twice // the input as uint32_t, and has no pointer or shared-state preconditions. unsafe { raw::bm106_scale(input) }}fn main() { println!("{}", scale(21)); }