@@ -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,18 @@ 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| {
196+ format ! ( "0x{:X}u64" , shared:: pack_static( i as u32 ) )
197+ . parse :: < proc_macro2:: TokenStream > ( )
198+ . unwrap ( )
199+ . into_iter ( )
200+ . next ( )
201+ . unwrap ( )
202+ } ) ;
193203
194204 let hashes: Vec < u32 > =
195205 atoms. iter ( ) . map ( |string| {
@@ -214,10 +224,11 @@ impl AtomType {
214224 Some ( ref doc) => quote ! ( #[ doc = #doc] ) ,
215225 None => quote ! ( )
216226 } ;
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 ) ) ;
227+ let new_term = |string : & str | proc_macro2:: Term :: new ( string, proc_macro2:: Span :: call_site ( ) ) ;
228+ let static_set_name = new_term ( & format ! ( "{}StaticSet" , type_name) ) ;
229+ let type_name = new_term ( type_name) ;
230+ let macro_name = new_term ( & * self . macro_name ) ;
231+ let path = iter:: repeat ( self . path . parse :: < proc_macro2:: TokenStream > ( ) . unwrap ( ) ) ;
221232
222233 quote ! {
223234 #atom_doc
@@ -228,9 +239,9 @@ impl AtomType {
228239 fn get( ) -> & ' static :: string_cache:: PhfStrSet {
229240 static SET : :: string_cache:: PhfStrSet = :: string_cache:: PhfStrSet {
230241 key: #key,
231- disps: & #disps ,
232- atoms: & #atoms ,
233- hashes: & # hashes
242+ disps: & [ # ( ( #disps0 , #disps1 ) ) , * ] ,
243+ atoms: & [ # ( #atoms_ref ) , * ] ,
244+ hashes: & [ # ( # hashes) , * ]
234245 } ;
235246 & SET
236247 }
@@ -242,7 +253,7 @@ impl AtomType {
242253 #[ macro_export]
243254 macro_rules! #macro_name {
244255 #(
245- ( #atoms ) => {
256+ ( #atoms_ref ) => {
246257 $crate :: #path {
247258 unsafe_data: #data,
248259 phantom: :: std:: marker:: PhantomData ,
0 commit comments