macro_rules! ascii_case_insensitive_phf_map { ($name: ident -> $ValueType: ty = { $( $key: tt => $value: expr ),+ }) => { ... }; ($name: ident -> $ValueType: ty = { $( $key: tt => $value: expr, )+ }) => { ... }; }
Expand description
Define a function $name(&str) -> Option<&'static $ValueType>
The function finds a match for the input string
in a phf
map
and returns a reference to the corresponding value.
Matching is case-insensitive in the ASCII range.
§Example:
fn color_rgb(input: &str) -> Option<(u8, u8, u8)> {
cssparser::ascii_case_insensitive_phf_map! {
keywords -> (u8, u8, u8) = {
"red" => (255, 0, 0),
"green" => (0, 255, 0),
"blue" => (0, 0, 255),
}
}
keywords::get(input).cloned()
}
You can also iterate over the map entries by using keywords::entries()
.