[][src]Crate compile_ops

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)); 

Macros

add

Performs a compile-time addition between comma-separated values,excluding that is prefixed with ! from they.

div

Performs a compile-time division between comma-separated values,excluding that is prefixed with ! from they.

mul

Performs a compile-time product between comma-separated values,excluding that is prefixed with ! from they.

ops

Performs any of the mathematical operations in Rust with their respective operator,^ for power. This macro also excludes anything that is prefixed with ! from the values.

pow

Performs a compile-time power between comma-separated values,excluding that is prefixed with ! from they.

rem

Performs a compile-time remainder between comma-separated values,excluding that is prefixed with ! from they.

sub

Performs a compile-time substraction between comma-separated values,excluding that is prefixed with ! from they.

ternary

Ternary operations with $bool:expr ? $code:expr $(! else_code)? syntax for shorter and more legible conditionals.