1extern crate proc_macro;
2
3use std::hash::{Hash, Hasher};
4
5use proc_macro::TokenStream;
6use quote::{quote, format_ident};
7use syn::{punctuated::Punctuated, parse_macro_input, Token, Ident};
8
9#[proc_macro]
10pub fn uq(input: TokenStream) -> TokenStream {
11 let idents: Punctuated<Ident, Token![,]> = parse_macro_input!(input with Punctuated::parse_terminated);
12
13 let mut iter = idents.into_iter();
14 let alias = iter.next().expect("First argument should be the alias.");
15 let ty = iter.next().expect("Second argument should be the type represented.");
16
17 let mut h = ahash::AHasher::default();
18 alias.hash(&mut h);
19
20 let tag = format_ident!("_{:x}_", h.finish());
21
22 quote! {
23 #[doc(hidden)]
24 #[derive(Default)]
25 struct #tag;
26 type #alias = Uq<#ty, #tag>;
27 }
28 .into()
29}