@@ -72,6 +72,7 @@ extern crate phf_generator;
7272extern crate phf_shared;
7373extern crate string_cache_shared as shared;
7474#[ macro_use] extern crate quote;
75+ extern crate proc_macro2;
7576
7677use std:: collections:: HashSet ;
7778use std:: fs:: File ;
@@ -169,7 +170,7 @@ impl AtomType {
169170 pub fn write_to < W > ( & mut self , mut destination : W ) -> io:: Result < ( ) > where W : Write {
170171 destination. write_all (
171172 self . to_tokens ( )
172- . as_str ( )
173+ . to_string ( )
173174 // Insert some newlines to make the generated code slightly easier to read.
174175 . replace ( " [ \" " , "[\n \" " )
175176 . replace ( "\" , " , "\" ,\n " )
@@ -187,9 +188,11 @@ impl AtomType {
187188 let atoms: Vec < & str > = self . atoms . iter ( ) . map ( |s| & * * s) . collect ( ) ;
188189 let hash_state = phf_generator:: generate_hash ( & atoms) ;
189190 let phf_generator:: HashState { key, disps, map } = hash_state;
191+ let ( disps0, disps1) : ( Vec < _ > , Vec < _ > ) = disps. into_iter ( ) . unzip ( ) ;
190192 let atoms: Vec < & str > = map. iter ( ) . map ( |& idx| atoms[ idx] ) . collect ( ) ;
193+ let atoms_ref = & atoms;
191194 let empty_string_index = atoms. iter ( ) . position ( |s| s. is_empty ( ) ) . unwrap ( ) as u32 ;
192- let data = ( 0 ..atoms. len ( ) ) . map ( |i| quote :: Hex ( shared:: pack_static ( i as u32 ) ) ) ;
195+ let data = ( 0 ..atoms. len ( ) ) . map ( |i| proc_macro2 :: Literal :: u64_suffixed ( shared:: pack_static ( i as u32 ) ) ) ;
193196
194197 let hashes: Vec < u32 > =
195198 atoms. iter ( ) . map ( |string| {
@@ -214,10 +217,11 @@ impl AtomType {
214217 Some ( ref doc) => quote ! ( #[ doc = #doc] ) ,
215218 None => quote ! ( )
216219 } ;
217- let static_set_name = quote:: Ident :: from ( format ! ( "{}StaticSet" , type_name) ) ;
218- let type_name = quote:: Ident :: from ( type_name) ;
219- let macro_name = quote:: Ident :: from ( & * self . macro_name ) ;
220- let path = iter:: repeat ( quote:: Ident :: from ( & * self . path ) ) ;
220+ let produce_term = |string : & str | proc_macro2:: Term :: new ( string, proc_macro2:: Span :: call_site ( ) ) ;
221+ let static_set_name = produce_term ( & format ! ( "{}StaticSet" , type_name) ) ;
222+ let type_name = produce_term ( type_name) ;
223+ let macro_name = produce_term ( & * self . macro_name ) ;
224+ let path = iter:: repeat ( produce_term ( & * self . path ) ) ;
221225
222226 quote ! {
223227 #atom_doc
@@ -228,9 +232,9 @@ impl AtomType {
228232 fn get( ) -> & ' static :: string_cache:: PhfStrSet {
229233 static SET : :: string_cache:: PhfStrSet = :: string_cache:: PhfStrSet {
230234 key: #key,
231- disps: & #disps ,
232- atoms: & #atoms ,
233- hashes: & # hashes
235+ disps: & [ # ( ( #disps0 , #disps1 ) ) , * ] ,
236+ atoms: & [ # ( #atoms_ref ) , * ] ,
237+ hashes: & [ # ( # hashes) , * ]
234238 } ;
235239 & SET
236240 }
@@ -242,7 +246,7 @@ impl AtomType {
242246 #[ macro_export]
243247 macro_rules! #macro_name {
244248 #(
245- ( #atoms ) => {
249+ ( #atoms_ref ) => {
246250 $crate :: #path {
247251 unsafe_data: #data,
248252 phantom: :: std:: marker:: PhantomData ,
0 commit comments