preprocessor 0.1.0

Compile-time computation macro library — analyzes computable sub-expressions in code and evaluates parts that can be executed at compile time
Documentation

preprocessor

version status

English | 简体中文

Compile-time computation macro library — analyzes computable sub-expressions in code and evaluates parts that can be executed at compile time.

Installation

cargo add preprocessor
cargo add chrono # Required for the test code below

Usage

#[optimize] — Function-level attribute macro

#[preprocessor::optimize]
fn compute() -> String {
    chrono::Local::now()
        .naive_local()
        .format("%Y-%m-%d %H:%M:%S")
        .to_string()
}

fn main() {
    let time = compute();
    println!("build_time: {time}");
}

op! — Expression-level macro

fn main() {
    let time = preprocessor::op!(
        chrono::Local::now()
            .naive_local()
            .format("%Y-%m-%d %H:%M:%S")
            .to_string()
    );
    println!("build_time: {time}");
}