| Crates.io | macro_optim |
| lib.rs | macro_optim |
| version | 1.0.0 |
| created_at | 2024-09-14 14:43:43.729355+00 |
| updated_at | 2024-09-14 14:43:43.729355+00 |
| description | A Rust procedural macro crate for optimizing and simplifying various expressions at compile time. |
| homepage | https://github.com/voltageddebunked/macro_optim |
| repository | https://github.com/voltageddebunked/macro_optim |
| max_upload_size | |
| id | 1374844 |
| size | 16,005 |
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.
Add macro_optim to your Cargo.toml:
[dependencies]
macro_optim = "1.0.0" # Replace with the appropriate version
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.
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.
Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.
This crate is licensed under the Apache 2.0 License. See the LICENSE file for more details.