@@ -134,18 +134,18 @@ macro_rules! match_ignore_ascii_case {
134134 // finished parsing
135135 ( @inner $value: expr, ( ) -> ( $( ( $string: expr => $result: expr) ) * ) $fallback: expr ) => {
136136 {
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 ) + )
141139 }
142140
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+ }
149149 }
150150 }
151151 } ;
@@ -156,11 +156,11 @@ macro_rules! match_ignore_ascii_case {
156156 } ;
157157}
158158
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>`
161160///
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.
164164/// Matching is case-insensitive in the ASCII range.
165165///
166166/// The `phf` and `cssparser_macros` crates must also be imported at the crate root
@@ -176,30 +176,25 @@ macro_rules! match_ignore_ascii_case {
176176///
177177/// fn color_rgb(input: &str) -> Option<(u8, u8, u8)> {
178178/// ascii_case_insensitive_phf_map! {
179- /// KEYWORDS: Map< (u8, u8, u8)> = {
179+ /// keyword -> (u8, u8, u8) = {
180180/// "red" => (255, 0, 0),
181181/// "green" => (0, 255, 0),
182182/// "blue" => (0, 0, 255),
183183/// }
184184/// }
185- /// KEYWORDS::get (input).cloned()
185+ /// keyword (input).cloned()
186186/// }
187187#[ macro_export]
188188macro_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+ }
197194
198- impl $Name {
199- #[ inline]
200- fn get( input: & str ) -> Option <& ' static $ValueType> {
195+ {
201196 _cssparser_internal__to_lowercase!( input => lowercase, $( $key) ,+) ;
202- lowercase. and_then( |string| $Name :: map ( ) . get( string ) )
197+ lowercase. and_then( |s| MAP . get( s ) )
203198 }
204199 }
205200 }
@@ -216,10 +211,8 @@ macro_rules! ascii_case_insensitive_phf_map {
216211#[ doc( hidden) ]
217212macro_rules! _cssparser_internal__to_lowercase {
218213 ( $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 ) + )
223216 }
224217
225218 // mem::uninitialized() is ok because `buffer` is only used in `_internal__to_lowercase`,
@@ -235,6 +228,21 @@ macro_rules! _cssparser_internal__to_lowercase {
235228 }
236229}
237230
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+
238246/// Implementation detail of match_ignore_ascii_case! and ascii_case_insensitive_phf_map! macros.
239247///
240248/// **This function is not part of the public API. It can change or be removed between any verisons.**
0 commit comments