Macro num_alias::int_alias [] [src]

macro_rules! int_alias {
    ($alias:ident, $type:ty) => { ... };
    ($alias:ident, $type:ty, $lb:expr => $hb:expr) => { ... };
}

A simple macro to declare alias for Integer types and implement arithmetics.

Concretely, it implements for the alias type, Add, Sub, Mul, Div, Rem, AddAssign, SubAssign, MulAssign, DivAssign, RemAssign, Deref(for accessing inner value).

In addition, Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd are Derived.

If not declared with range, Default is also derived.

Examples

Basic usage: just aliasing int.

#[macro_use]
extern crate num_alias;
fn main() {
    int_alias!(Val, i32);
    let a = Val(5);
    let b = Val(4);
    let c = a * b;
}

In addition, you can declare an alias with a 'range checked' constructor.

#[macro_use]
extern crate num_alias;
fn main() {
    // declare alias with range[3, 6)
    int_alias!(Val, i32, 3 => 6);
    let a = Val(5);
    let b = Val(4);
    // this code panics
    let c = a * b;
}