macro_optim

Crates.iomacro_optim
lib.rsmacro_optim
version1.0.0
sourcesrc
created_at2024-09-14 14:43:43.729355
updated_at2024-09-14 14:43:43.729355
descriptionA Rust procedural macro crate for optimizing and simplifying various expressions at compile time.
homepagehttps://github.com/voltageddebunked/macro_optim
repositoryhttps://github.com/voltageddebunked/macro_optim
max_upload_size
id1374844
size16,005
Voltaged (VoltagedDebunked)

documentation

https://docs.rs/macro_optim

README

macro_optim

macro_optim is a Rust procedural macro crate designed to optimize mathematical expressions with procedural macros, used for heavy mathematical computations, like rendering. It can handle addition and multiplication of integer and floating-point literals by evaluating them and replacing them with the result. It optimizes the code at compile time.

Features

  • Compile-time Expression Optimization: Optimize integer and floating-point addition and multiplication.
  • Arithmetic Evaluation: Automatically replace constant expressions with their evaluated results.

Installation

Add macro_optim to your Cargo.toml:

[dependencies]
macro_optim = "1.0.0"  # Replace with the appropriate version

Usage

To use the macro_optim attribute macro, annotate your code with #[macro_optim]. This macro will evaluate and replace constant expressions in the annotated item.

Example

use macro_optim::macro_optim;

#[macro_optim]
fn optimized_expr() -> i32 {
    let result = 2 + 3 * 4; // This will be optimized to 14
    result
}

fn main() {
    println!("{}", optimized_expr()); // Prints 14
}

In the example above, the expression 2 + 3 * 4 will be evaluated to 14 at compile time.

Limitations

  • Currently supports only addition and multiplication.
  • Supports only integer and floating-point literals.
  • Complex expressions or non-literal values are not optimized.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.

License

This crate is licensed under the Apache 2.0 License. See the LICENSE file for more details.

Commit count: 0

cargo fmt