Macro cssparser::ascii_case_insensitive_phf_map
[−]
[src]
macro_rules! ascii_case_insensitive_phf_map { ($Name: ident : Map<$ValueType: ty> = { $( $key: expr => $value: expr, )* }) => { ... }; }
Define a placeholder type $Name
with a method fn get(input: &str) -> Option<&'static $ValueType>
.
This method uses finds a match for the input string
in a phf
map.
Matching is case-insensitive in the ASCII range.
Requirements:
- The
phf
andcssparser_macros
crates must also be imported at the crate root - The values must be given a strings that contain Rust syntax for a constant expression.
Example:
extern crate phf; #[macro_use] extern crate cssparser; #[macro_use] extern crate cssparser_macros; fn color_rgb(input: &str) -> Option<(u8, u8, u8)> { ascii_case_insensitive_phf_map! { KEYWORDS: Map<(u8, u8, u8)> = { "red" => "(255, 0, 0)", "green" => "(0, 255, 0)", "blue" => "(0, 0, 255)", } } KEYWORDS::get(input).cloned() }