Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..73e8dce --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,29 @@ +//! a lil macro crate. +//! +//! provides a handy macro for converting `a + b` to `a.add(b)` for when you cant easily overload the `Add` trait, +//! and some traits that provide [`f*_algebraic`](algebraic::math) and [`f*_fast`](fast::math) implementations. (requires nightly) +#![allow(internal_features)] +#![cfg_attr( + feature = "modules", + feature(doc_auto_cfg, core_intrinsics, hint_assert_unchecked) +)] + +#[cfg(feature = "modules")] +pub mod algebraic; +#[cfg(feature = "modules")] +pub mod fast; + +/// Lower math to method calls. Only useful if you define the functions. +/// ``` +/// # use std::ops::*; +/// let [a, b, c] = [5i32, 6, 7]; +/// assert_eq!(lower::math! { a * *&b + -c }, a * *&b + -c); +/// // expands to +/// // a.mul((&b).deref()).add(c.neg()) +/// ``` +#[macro_export] +macro_rules! math { + ($($x:tt)+) => { + lower_macros::math! { $($x)+ } + }; +} |