bruteforce_macros/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3extern crate proc_macro;
4
5#[cfg(not(feature = "std"))]
6extern crate no_std_compat as std;
7
8use proc_macro::TokenStream;
9
10use std::collections::HashSet;
11use std::prelude::v1::*; // needed for std-compat
12
13use quote::quote;
14
15/// Converts an string into a slice
16#[doc(hidden)]
17#[proc_macro]
18pub fn charset_string(item: TokenStream) -> TokenStream {
19    assert!(!item.is_empty(), "Cannot parse empty string as charset");
20    let chars: HashSet<char> = item.to_string().chars().collect(); // hashset, because duplicates are not permitted
21    let iter = chars.into_iter();
22    TokenStream::from(quote! {
23        let slice = &[#(#iter),*];
24    })
25}