Expand description
§preprocessor
Compile-time computation macros for Rust. Analyzes code for computable sub-expressions and evaluates them at compile time, so the final binary contains only the results.
§Macros
| Macro | Scope | Description |
|---|---|---|
#[preprocessor::optimize] | Function | Optimizes all evaluable expressions in a function body |
preprocessor::op!(...) | Expression | Evaluates a single expression at compile time |
§Features
| Feature | Description |
|---|---|
disabled | Disables all compile-time optimization; macros become transparent passthrough |
§Example
use preprocessor::op;
// Compile-time evaluation
let result = op!(1 + 2 * 3); // → 7
// With free variables — compile error
// let x = 5;
// let y = op!(x + 1); // ERROR: cannot evaluate at compile timeⓘ
use preprocessor::optimize;
#[optimize]
fn compute() -> i32 {
let a = 1 + 2; // → 3
let b = 4 * 5; // → 20
a + b
}Macros§
- op
preprocessor::op!(...)— Expression-level macro for compile-time evaluation.