@@ -172,32 +172,37 @@ macro_rules! define_proc_macros {
172
172
$(
173
173
$( #[ $attr] ) *
174
174
#[ proc_macro_derive( $proc_macro_name) ]
175
- pub fn $proc_macro_name( input: :: proc_macro:: TokenStream ) -> :: proc_macro:: TokenStream {
176
- // Use another function to hide this one’s local variables from $block
177
- #[ inline]
178
- fn implementation( $input: & str ) -> String $body
179
-
180
- let input = input. to_string( ) ;
181
- let mut normalized = String :: with_capacity( input. len( ) ) ;
182
- for piece in input. split_whitespace( ) {
183
- normalized. push_str( piece) ;
184
- normalized. push( ' ' ) ;
185
- }
186
-
187
- let prefix = "#[allow(unused)] enum ProceduralMasqueradeDummyType { Input = (0, stringify!(" ;
188
- let suffix = ")).0, } " ;
189
- assert!( normalized. starts_with( prefix) , "expected prefix not found in {:?}" , input) ;
190
- assert!( normalized. ends_with( suffix) , "expected suffix not found in {:?}" , input) ;
191
-
192
- let start = prefix. len( ) ;
193
- let end = normalized. len( ) - suffix. len( ) ;
194
- let output = implementation( & normalized[ start..end] ) ;
195
- output. parse( ) . unwrap( )
175
+ pub fn $proc_macro_name( derive_input: :: proc_macro:: TokenStream )
176
+ -> :: proc_macro:: TokenStream {
177
+ let $input = derive_input. to_string( ) ;
178
+ let $input: & str = & $crate:: _extract_input( & $input) ;
179
+ $body. parse( ) . unwrap( )
196
180
}
197
181
) +
198
182
}
199
183
}
200
184
185
+ /// Implementation detail of `define_proc_macros!`.
186
+ ///
187
+ /// **This function is not part of the public API. It can change or be removed between any versions.**
188
+ #[ doc( hidden) ]
189
+ pub fn _extract_input ( derive_input : & str ) -> String {
190
+ let mut normalized = String :: with_capacity ( derive_input. len ( ) ) ;
191
+ for piece in derive_input. split_whitespace ( ) {
192
+ normalized. push_str ( piece) ;
193
+ normalized. push ( ' ' ) ;
194
+ }
195
+
196
+ let prefix = "#[allow(unused)] enum ProceduralMasqueradeDummyType { Input = (0, stringify!(" ;
197
+ let suffix = ")).0, } " ;
198
+ assert ! ( normalized. starts_with( prefix) , "expected prefix not found in {:?}" , derive_input) ;
199
+ assert ! ( normalized. ends_with( suffix) , "expected suffix not found in {:?}" , derive_input) ;
200
+
201
+ let start = prefix. len ( ) ;
202
+ let end = normalized. len ( ) - suffix. len ( ) ;
203
+ normalized[ start..end] . to_owned ( )
204
+ }
205
+
201
206
/// This macro expands to the definition of another macro (whose name is given as a parameter).
202
207
///
203
208
/// See crate documentation for details.
0 commit comments