From 29a7d58b4181cceba799e184a28ddba8998ba2dc Mon Sep 17 00:00:00 2001 From: Magnus Hoff Date: Thu, 2 Nov 2017 15:19:23 +0100 Subject: [PATCH] Use maplit for static hash map literal --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/main.rs | 1 + src/wiki_lookup.rs | 30 +++++++++--------------------- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 42033ae..36851cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -344,6 +344,11 @@ dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "maplit" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "matches" version = "0.1.6" @@ -575,6 +580,7 @@ dependencies = [ "hyper 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "libsqlite3-sys 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "maplit 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.0.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -989,6 +995,7 @@ dependencies = [ "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf0336886480e671965f794bc9b6fce88503563013d1bfb7a502c81fe3ac527" "checksum magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40d014c7011ac470ae28e2f76a02bfea4a8480f73e701353b49ad7a8d75f4699" +"checksum maplit 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ed95049d40b8a1a7691adbabca028ad481f7e6a2921ce4846e1ee168b4e4ca5" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4" "checksum mime 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "153f98dde2b135dece079e5478ee400ae1bab13afa52d66590eacfc40e912435" diff --git a/Cargo.toml b/Cargo.toml index 302107d..bdb659f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ futures = "0.1" futures-cpupool = "0.1" hyper = "0.11" lazy_static = "0.2" +maplit = "1" percent-encoding = "1.0.0" r2d2 = "0.7" r2d2-diesel = "0.16" diff --git a/src/main.rs b/src/main.rs index 180c82e..0127d55 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ #[macro_use] extern crate diesel_codegen; #[macro_use] extern crate hyper; #[macro_use] extern crate lazy_static; +#[macro_use] extern crate maplit; #[macro_use] extern crate serde_derive; #[macro_use] extern crate static_resource_derive; diff --git a/src/wiki_lookup.rs b/src/wiki_lookup.rs index f37e153..165c36d 100644 --- a/src/wiki_lookup.rs +++ b/src/wiki_lookup.rs @@ -16,30 +16,18 @@ type BoxResource = Box; type ResourceFn = Box BoxResource + Sync + Send>; lazy_static! { - static ref ASSETS_MAP: HashMap = { - let mut map = HashMap::new(); + static ref ASSETS_MAP: HashMap = hashmap!{ + format!("style-{}.css", StyleCss::checksum()) => + Box::new(|| Box::new(StyleCss) as BoxResource) as ResourceFn, - map.insert( - format!("style-{}.css", StyleCss::checksum()), - Box::new(|| Box::new(StyleCss) as BoxResource) as ResourceFn - ); + format!("script-{}.js", ScriptJs::checksum()) => + Box::new(|| Box::new(ScriptJs) as BoxResource) as ResourceFn, - map.insert( - format!("script-{}.js", ScriptJs::checksum()), - Box::new(|| Box::new(ScriptJs) as BoxResource) as ResourceFn - ); + format!("search-{}.js", SearchJs::checksum()) => + Box::new(|| Box::new(SearchJs) as BoxResource) as ResourceFn, - map.insert( - format!("search-{}.js", SearchJs::checksum()), - Box::new(|| Box::new(SearchJs) as BoxResource) as ResourceFn - ); - - map.insert( - format!("amatic-sc-v9-latin-regular.woff"), - Box::new(|| Box::new(AmaticFont) as BoxResource) as ResourceFn - ); - - map + format!("amatic-sc-v9-latin-regular.woff") => + Box::new(|| Box::new(AmaticFont) as BoxResource) as ResourceFn, }; }