match_by_hash/
lib.rs

1use input::Input;
2use proc_macro::TokenStream as TokenStream1;
3
4mod input;
5mod output;
6
7/// # Example
8/// ```rust
9/// use match_by_hash::match_by_hash;
10///
11/// const fn hash(s: &str) -> usize { s.len() }
12///
13/// let result = match_by_hash!(match hash("target") {
14///     "other" => 9,
15///     "target" => 42,
16///     _ => 999,
17/// });
18/// assert_eq!(result, 42);
19/// ```
20#[proc_macro]
21pub fn match_by_hash(input: TokenStream1) -> TokenStream1 {
22    let input = syn::parse_macro_input!(input as Input);
23    output::into_stream(&input).into()
24}