| Crates.io | unhygienic2 |
| lib.rs | unhygienic2 |
| version | 0.1.0 |
| created_at | 2022-09-04 09:15:47.067791+00 |
| updated_at | 2022-09-04 09:15:47.067791+00 |
| description | A dead simple macro to erase macro hygiene. |
| homepage | |
| repository | https://github.com/Trard/unhygienic2 |
| max_upload_size | |
| id | 658197 |
| size | 4,539 |
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.
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);
}