Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created January 24, 2020 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/8ad6e24ebe1eb53aa92c0522b8c14261 to your computer and use it in GitHub Desktop.
Save rust-play/8ad6e24ebe1eb53aa92c0522b8c14261 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
use lazy_static; // 1.4.0
use std::collections::HashMap;
#[derive(Copy, Clone, Debug)]
pub struct Server {}
lazy_static::lazy_static! {
static ref SERVER1: Server = Server {};
static ref SERVER2: Server = Server {};
pub static ref RAW: HashMap<&'static str, &'static Server> = [
("domain1.com", &*SERVER1),
("domain1.org", &*SERVER1),
("domain2.com", &*SERVER2),
].iter().copied().collect();
}
fn main() {
let server = RAW.get("domain1.org");
println!("{:?}", server);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment