#macro #macro-use #macro-utils

macro-utils

Some macros to make code writing more elegant and funny

4 releases

Uses old Rust 2015

0.1.3 May 1, 2019
0.1.2 Jul 7, 2018
0.1.1 Jul 6, 2018
0.1.0 Jul 6, 2018

#1533 in Rust patterns

Download history 223/week @ 2024-12-13 153/week @ 2024-12-20 143/week @ 2024-12-27 176/week @ 2025-01-03 244/week @ 2025-01-10 217/week @ 2025-01-17 163/week @ 2025-01-24 294/week @ 2025-01-31 505/week @ 2025-02-07 346/week @ 2025-02-14 319/week @ 2025-02-21 276/week @ 2025-02-28 204/week @ 2025-03-07 429/week @ 2025-03-14 282/week @ 2025-03-21 196/week @ 2025-03-28

1,154 downloads per month

MIT license

17KB
186 lines

Build Status Build status

macro-utils

Some macros to help writing better code or just having fun.

Usage

To use it in your project, just add the following lines:

#[macro_use]
extern crate macro_utils;

Examples

#[macro_use]
extern crate macro_utils;

fn main() {
    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" } };
}

No runtime deps