#macro #proc-macro #unhygienic #hygienic

macro unhygienic2

A dead simple macro to erase macro hygiene

1 unstable release

0.1.0 Sep 4, 2022

#1490 in #proc-macro

Download history 11/week @ 2024-02-23 11/week @ 2024-03-01 4/week @ 2024-03-08 2/week @ 2024-03-15 23/week @ 2024-03-29 5/week @ 2024-04-05 57/week @ 2024-04-12 7/week @ 2024-04-19

64 downloads per month
Used in 2 crates (via impl_serialize)

MIT license

4KB

Unhygienic2

A dead simple macro to erase macro hygiene. This stringifies the input, then reparses it in the caller's context.

First unhygienic based on proc_macro_hack. Since 1.45 Rust have native support #[proc_macro]. Therefore, proc_macro_hack isn't neeeded.

Example

use unhygienic2::unhygienic;

macro_rules! declare {
    ($exp:expr) => {
        unhygienic! {
            fn func() -> i32 {
                let a = 5;

                $exp
            }
        }
    }
}

declare!({ a + 1 });

fn main() {
    assert_eq!(func(), 6);
}

lib.rs:

A dead simple macro to erase macro hygiene. This stringifies the input, then reparses it in the caller's context. First unhygienic based on proc_macro_hack. Since 1.45 Rust have native support [proc_macro]. Therefore, proc_macro_hack isn't neeeded.

Example

use unhygienic2::unhygienic;

macro_rules! declare {
    ($exp:expr) => {
        unhygienic! {
            fn func() -> i32 {
                let a = 5;

                $exp
            }
        }
    }
}

declare!({ a + 1 });

fn main() {
    assert_eq!(func(), 6);
}

No runtime deps