macro

include! — Insert Rust source at compile time

Insert source as an item or expression, according to the surrounding syntax. Paths are resolved relative to the file containing the invocation using the build host’s path rules. Included code participates in the surrounding name resolution; use ordinary modules for most handwritten multi-file programs. Only include trusted source. Result: Depends on included syntax. Fixture prerequisites: quantity.expr (see catalog for exact contents). Expected output (not executed): 'Total: 20\n' Common mistake: Treating a text file as a string or expecting a separate module namespace.

Formal Syntax & Structure

rust syntaxrust
include!("relative/path.rs")

Working Example

Example Snippetrust
fn main() {    let quantity: u32 = include!("quantity.expr");    println!("Total: {}", quantity * 5);}
Rust Reference