@@ -134,18 +134,18 @@ macro_rules! match_ignore_ascii_case {
134
134
// finished parsing
135
135
( @inner $value: expr, ( ) -> ( $( ( $string: expr => $result: expr) ) * ) $fallback: expr ) => {
136
136
{
137
- #[ derive( cssparser__assert_ascii_lowercase) ]
138
- #[ allow( unused) ]
139
- enum Dummy {
140
- Input = ( 0 , stringify!( $( $string ) + ) ) . 0
137
+ _cssparser_internal__pretend_proc_macro! {
138
+ cssparser__assert_ascii_lowercase!( $( $string ) + )
141
139
}
142
140
143
- _cssparser_internal__to_lowercase!( $value => lowercase, $( $string) ,+) ;
144
- match lowercase {
145
- $(
146
- Some ( $string) => $result,
147
- ) +
148
- _ => $fallback
141
+ {
142
+ _cssparser_internal__to_lowercase!( $value => lowercase, $( $string) ,+) ;
143
+ match lowercase {
144
+ $(
145
+ Some ( $string) => $result,
146
+ ) +
147
+ _ => $fallback
148
+ }
149
149
}
150
150
}
151
151
} ;
@@ -156,11 +156,11 @@ macro_rules! match_ignore_ascii_case {
156
156
} ;
157
157
}
158
158
159
- /// Define a placeholder type `$Name`
160
- /// with a method `fn get(input: &str) -> Option<&'static $ValueType>`.
159
+ /// Define a function `$name(&str) -> Option<&'static $ValueType>`
161
160
///
162
- /// This method uses finds a match for the input string
163
- /// in a [`phf` map](https://github.com/sfackler/rust-phf).
161
+ /// The function finds a match for the input string
162
+ /// in a [`phf` map](https://github.com/sfackler/rust-phf)
163
+ /// and returns a reference to the corresponding value.
164
164
/// Matching is case-insensitive in the ASCII range.
165
165
///
166
166
/// The `phf` and `cssparser_macros` crates must also be imported at the crate root
@@ -176,30 +176,25 @@ macro_rules! match_ignore_ascii_case {
176
176
///
177
177
/// fn color_rgb(input: &str) -> Option<(u8, u8, u8)> {
178
178
/// ascii_case_insensitive_phf_map! {
179
- /// KEYWORDS: Map< (u8, u8, u8)> = {
179
+ /// keyword -> (u8, u8, u8) = {
180
180
/// "red" => (255, 0, 0),
181
181
/// "green" => (0, 255, 0),
182
182
/// "blue" => (0, 0, 255),
183
183
/// }
184
184
/// }
185
- /// KEYWORDS::get (input).cloned()
185
+ /// keyword (input).cloned()
186
186
/// }
187
187
#[ macro_export]
188
188
macro_rules! ascii_case_insensitive_phf_map {
189
- ( $Name: ident : Map <$ValueType: ty> = {
190
- $( $key: expr => $value: expr, ) *
191
- } ) => {
192
- #[ derive( cssparser__phf_map) ]
193
- #[ allow( unused) ]
194
- enum $Name {
195
- Input = ( 0 , stringify!( ( $ValueType) $( $key ( $value) ) + ) ) . 0
196
- }
189
+ ( $name: ident -> $ValueType: ty = { $( $key: expr => $value: expr, ) * } ) => {
190
+ fn $name( input: & str ) -> Option <& ' static $ValueType> {
191
+ _cssparser_internal__pretend_proc_macro! {
192
+ cssparser__phf_map!( ( $ValueType) $( $key ( $value) ) + )
193
+ }
197
194
198
- impl $Name {
199
- #[ inline]
200
- fn get( input: & str ) -> Option <& ' static $ValueType> {
195
+ {
201
196
_cssparser_internal__to_lowercase!( input => lowercase, $( $key) ,+) ;
202
- lowercase. and_then( |string| $Name :: map ( ) . get( string ) )
197
+ lowercase. and_then( |s| MAP . get( s ) )
203
198
}
204
199
}
205
200
}
@@ -216,10 +211,8 @@ macro_rules! ascii_case_insensitive_phf_map {
216
211
#[ doc( hidden) ]
217
212
macro_rules! _cssparser_internal__to_lowercase {
218
213
( $input: expr => $output: ident, $( $string: expr) ,+) => {
219
- #[ derive( cssparser__max_len) ]
220
- #[ allow( unused) ]
221
- enum Dummy2 {
222
- Input = ( 0 , stringify!( $( $string ) + ) ) . 0
214
+ _cssparser_internal__pretend_proc_macro! {
215
+ cssparser__max_len!( $( $string ) + )
223
216
}
224
217
225
218
// mem::uninitialized() is ok because `buffer` is only used in `_internal__to_lowercase`,
@@ -235,6 +228,21 @@ macro_rules! _cssparser_internal__to_lowercase {
235
228
}
236
229
}
237
230
231
+ /// Implementation detail of match_ignore_ascii_case! and ascii_case_insensitive_phf_map! macros.
232
+ ///
233
+ /// **This macro is not part of the public API. It can change or be removed between any versions.**
234
+ #[ macro_export]
235
+ #[ doc( hidden) ]
236
+ macro_rules! _cssparser_internal__pretend_proc_macro {
237
+ ( $macro_name: ident ! ( $( $tt: tt) * ) ) => {
238
+ #[ derive( $macro_name) ]
239
+ #[ allow( unused) ]
240
+ enum Dummy {
241
+ Input = ( 0 , stringify!( $( $tt ) * ) ) . 0
242
+ }
243
+ }
244
+ }
245
+
238
246
/// Implementation detail of match_ignore_ascii_case! and ascii_case_insensitive_phf_map! macros.
239
247
///
240
248
/// **This function is not part of the public API. It can change or be removed between any verisons.**
0 commit comments