Skip to content

Commit 788e81a

Browse files
committed
Improve ascii_case_insensitive_phf_map macro syntax
Signed-off-by: Nico Burns <nico@nicoburns.com>
1 parent 1ab661d commit 788e81a

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/color.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pub fn parse_hash_color(value: &[u8]) -> Result<(u8, u8, u8, f32), ()> {
174174
}
175175

176176
ascii_case_insensitive_phf_map! {
177-
named_colors -> (u8, u8, u8) = {
177+
static NAMED_COLORS : (u8, u8, u8) = {
178178
"black" => (0, 0, 0),
179179
"silver" => (192, 192, 192),
180180
"gray" => (128, 128, 128),
@@ -332,14 +332,14 @@ ascii_case_insensitive_phf_map! {
332332
#[allow(clippy::result_unit_err)]
333333
#[inline]
334334
pub fn parse_named_color(ident: &str) -> Result<(u8, u8, u8), ()> {
335-
named_colors::get(ident).copied().ok_or(())
335+
NAMED_COLORS::get(ident).copied().ok_or(())
336336
}
337337

338338
/// Returns an iterator over all named CSS colors.
339339
/// <https://drafts.csswg.org/css-color-4/#typedef-named-color>
340340
#[inline]
341341
pub fn all_named_colors() -> impl Iterator<Item = (&'static str, (u8, u8, u8))> {
342-
named_colors::entries().map(|(k, v)| (*k, *v))
342+
NAMED_COLORS::entries().map(|(k, v)| (*k, *v))
343343
}
344344

345345
#[inline]

src/macros.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,23 @@ macro_rules! match_ignore_ascii_case {
8787
///
8888
/// fn color_rgb(input: &str) -> Option<(u8, u8, u8)> {
8989
/// cssparser::ascii_case_insensitive_phf_map! {
90-
/// keywords -> (u8, u8, u8) = {
90+
/// static KEYWORDS : (u8, u8, u8) = {
9191
/// "red" => (255, 0, 0),
9292
/// "green" => (0, 255, 0),
9393
/// "blue" => (0, 0, 255),
9494
/// }
9595
/// }
96-
/// keywords::get(input).cloned()
96+
/// KEYWORDS::get(input).cloned()
9797
/// }
9898
/// ```
9999
///
100100
/// You can also iterate over the map entries by using `keywords::entries()`.
101101
#[macro_export]
102102
macro_rules! ascii_case_insensitive_phf_map {
103-
($name: ident -> $ValueType: ty = { $( $key: tt => $value: expr ),+ }) => {
104-
ascii_case_insensitive_phf_map!($name -> $ValueType = { $( $key => $value, )+ })
103+
(static $name:ident : $ValueType:ty = { $( $key:tt => $value:expr ),+ }) => {
104+
ascii_case_insensitive_phf_map!(static $name : $ValueType = { $( $key => $value, )+ })
105105
};
106-
($name: ident -> $ValueType: ty = { $( $key: tt => $value: expr, )+ }) => {
106+
(static $name:ident : $ValueType:ty = { $( $key:tt => $value:expr, )+ }) => {
107107
use $crate::_cssparser_internal_phf as phf;
108108

109109
#[inline(always)]
@@ -124,7 +124,7 @@ macro_rules! ascii_case_insensitive_phf_map {
124124
maxlen
125125
};
126126

127-
static MAP: phf::Map<&'static str, $ValueType> = phf::phf_map! {
127+
static __MAP: phf::Map<&'static str, $ValueType> = phf::phf_map! {
128128
$(
129129
$key => $value,
130130
)*
@@ -140,12 +140,12 @@ macro_rules! ascii_case_insensitive_phf_map {
140140
impl $name {
141141
#[allow(dead_code)]
142142
fn entries() -> impl Iterator<Item = (&'static &'static str, &'static $ValueType)> {
143-
MAP.entries()
143+
__MAP.entries()
144144
}
145145

146146
fn get(input: &str) -> Option<&'static $ValueType> {
147147
$crate::_cssparser_internal_to_lowercase!(input, MAX_LENGTH => lowercase);
148-
MAP.get(lowercase?)
148+
__MAP.get(lowercase?)
149149
}
150150
}
151151
}

src/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,12 +1086,12 @@ fn one_component_value_to_json(token: Token, input: &mut Parser) -> Value {
10861086
#[test]
10871087
fn procedural_masquerade_whitespace() {
10881088
ascii_case_insensitive_phf_map! {
1089-
map -> () = {
1089+
static MAP : () = {
10901090
" \t\n" => ()
10911091
}
10921092
}
1093-
assert_eq!(map::get(" \t\n"), Some(&()));
1094-
assert_eq!(map::get(" "), None);
1093+
assert_eq!(MAP::get(" \t\n"), Some(&()));
1094+
assert_eq!(MAP::get(" "), None);
10951095

10961096
match_ignore_ascii_case! { " \t\n",
10971097
" " => panic!("1"),

0 commit comments

Comments
 (0)