#operations #macro #compiled #equations #proc-macro #arithmetica

nightly macro no-std compile_ops

Compile time operations to not affect your performance and constness with ecuations you can encode

4 releases

0.1.3 Jan 3, 2020
0.1.2 Dec 27, 2019
0.1.1 Dec 24, 2019
0.1.0 Dec 23, 2019

#31 in #equations


Used in 2 crates (via col_macros)

Unlicense

17KB
323 lines

compile_ops

This Rust library provides macros that expand to the result of operations like addition,substraction,division,multiplication or power and a macro for join them all.

All the macros support exclusion of expressions thought '!' before they,useful when you cannot prevent code to expand inside the tokens passed;nowadays only possible thought the MBE expansion bucles.

This crate is no_std.

Examples

#![feature(proc_macro_hygiene)]

use compile_ops::*;

assert_eq!(2, add!(1!5, !5, 1)); // five it is not invited...
assert_eq!(2, sub!(3, 1));
assert_eq!(2, mul!(2, 1));
assert_eq!(2, div!(4, 2));
assert_eq!(2, rem!(11, 3));

assert_eq!(2, ops!(2 % 2 + 2 * 2 ^ 1 / 1 - 2)); 

lib.rs:

This crate provides macros that expand to the result of operations like addition,substraction,division,multiplication or power and a macro for join them all.

All the macros support exclusion of expressions thought '!' before they,useful when you cannot prevent code to expand inside the tokens passed;nowadays only possible thought the MBE expansion bucles.

This crate is no_std.

Examples

#![feature(proc_macro_hygiene)]

use compile_ops::*;

assert_eq!(2, add!(1!5, !5, 1)); // five it is not invited...
assert_eq!(2, sub!(3, 1));
assert_eq!(2, mul!(2, 1));
assert_eq!(2, div!(4, 2));
assert_eq!(2, rem!(11, 3));

assert_eq!(2, ops!(2 % 2 + 2 * 2 ^ 1 / 1 - 2)); 

No runtime deps