Macro phf::phf_map

source ·
phf_map!() { /* proc-macro */ }
Expand description

Macro to create a static (compile-time) Map.

Requires the macros feature.

Supported key expressions are:

  • literals: bools, (byte) strings, bytes, chars, and integers (these must have a type suffix)
  • arrays of u8 integers
  • dereferenced byte string literals
  • UniCase::unicode(string) or UniCase::ascii(string) if the unicase feature is enabled

Example

use phf::{phf_map, Map};

static MY_MAP: Map<&'static str, u32> = phf_map! {
    "hello" => 1,
    "world" => 2,
};

fn main () {
    assert_eq!(MY_MAP["hello"], 1);
}