[][src]Crate macro_utils

Some useful and funny macros.

To be able to use it, import is as follows:

#[macro_use]
extern crate macro_utils;

Examples

let s = "bateau";

if_match! {
    s == "voiture" => println!("It rolls!"),
    s == "avion"   => println!("It flies!"),
    s == "pieds"   => println!("It walks!"),
    s == "fusée"   => println!("It goes through space!"),
    s == "bateau"  => println!("It moves on water!"),
    else           => println!("I dont't know how it moves...")
}

let y = 4;
let x = tern_c! { (y & 1 == 0) ? { "even" } : { "odd" } };
let x = tern_python! { { "it's even" } if (y & 1 == 0) else { "it's odd" } };
let x = tern_haskell! { if (y & 1 == 0) then { "it's even" } else { "it's odd" } };

Macros

if_match

A macro to make big else if conditions easier to read:

tern_c

You miss C-like ternary conditions? Why not having them in Rust then?

tern_haskell

You miss Haskell-like ternary conditions? Why not having them in Rust then?

tern_py

The same as tern_python macro but shorter:

tern_python

You miss Python-like ternary conditions? Why not having them in Rust then?