Crate num_alias [] [src]

Simple macros to declare 'type and range checked' aliases for integers and floats.

Examples

Basic usage: just aliasing float.

#[macro_use]
extern crate num_alias;
fn main() {
    float_alias!(Fval, f64);
    let a = Fval(5.0);
    let b = Fval(4.0);
    let c = (a * b).sqrt();
}

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

Note: When using with range, these macros declare aliases not as Tuple Struct, but as Normal Struct and declare global functions with their name(In above example, fn Val(i: i32)-> Val is declared).

This spec is for ease of use, but make alias' range safety imcomplete(If you can construct an alias with default constructor(like Val{inner: 5}), range cheking won't run.)

Macros

float_alias

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

int_alias

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