Rust best practices when specifying a constant hash map [duplicate]

You can use https://crates.io/crates/lazy_static (lazily executed at runtime).

I personally use https://crates.io/crates/phf (compile-time static collections) for this if the data is truly static.

use phf::{phf_map};

static COUNTRIES: phf::Map<&'static str, &'static str> = phf_map! {
    "US" => "United States",
    "UK" => "United Kingdom",
};

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)