unhygienic2

Crates.iounhygienic2
lib.rsunhygienic2
version0.1.0
sourcesrc
created_at2022-09-04 09:15:47.067791
updated_at2022-09-04 09:15:47.067791
descriptionA dead simple macro to erase macro hygiene.
homepage
repositoryhttps://github.com/Trard/unhygienic2
max_upload_size
id658197
size4,539
Eduard Baturin (Trard)

documentation

https://docs.rs/Trard/unhygienic2

README

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);
}
Commit count: 3

cargo fmt