Skip to main content

Crate preprocessor

Crate preprocessor 

Source
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

MacroScopeDescription
#[preprocessor::optimize]FunctionOptimizes all evaluable expressions in a function body
preprocessor::op!(...)ExpressionEvaluates a single expression at compile time

§Features

FeatureDescription
disabledDisables 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 — passed through
let x = 5;
let y = op!(x + 1); // → x + 1 (unchanged)
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.

Attribute Macros§

optimize
#[preprocessor::optimize] — Function-level attribute macro for compile-time optimization.
prelude
#[preprocessor::prelude] — Crate-level attribute macro for automatic dependency resolution.