diff --git a/Cargo.lock b/Cargo.lock index 2e321b6..1bee553 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1129,6 +1129,11 @@ dependencies = [ "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "once_cell" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "opaque-debug" version = "0.2.3" @@ -1223,9 +1228,9 @@ dependencies = [ "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2535,6 +2540,7 @@ dependencies = [ "checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" "checksum num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c81ffc11c212fa327657cb19dd85eb7419e163b5b076bede2bdb5c974c07e4" "checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72" +"checksum once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "891f486f630e5c5a4916c7e16c4b24a53e78c860b646e9f8e005e4f16847bfed" "checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" "checksum openssl 0.10.26 (registry+https://github.com/rust-lang/crates.io-index)" = "3a3cc5799d98e1088141b8e01ff760112bbd9f19d850c124500566ca6901a585" "checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" diff --git a/Cargo.toml b/Cargo.toml index 9ce4fa4..b9d8f29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,9 +16,9 @@ env_logger = { version = "0.6.0", default-features = false } futures = "0.1.28" futures03 = { version = "0.3.1", package = "futures", features = ["compat"] } itertools = "0.8.1" -lazy_static = "1.3.0" log = "0.4.6" mime = "0.3.13" +once_cell = "1.2.0" pulldown-cmark = "0.5.0" rand = "0.7.0" reqwest = "0.9.19" diff --git a/src/models/paste.rs b/src/models/paste.rs index 5bc43d7..4b08e4d 100644 --- a/src/models/paste.rs +++ b/src/models/paste.rs @@ -5,8 +5,8 @@ use ammonia::Builder; use chrono::{DateTime, Utc}; use diesel::prelude::*; use itertools::Itertools; -use lazy_static::lazy_static; use log::info; +use once_cell::sync::Lazy; use pulldown_cmark::{Options, Parser}; use rand::seq::SliceRandom; use std::iter; @@ -144,27 +144,25 @@ impl ExternPaste { } fn render_markdown(markdown: &str) -> String { - lazy_static! { - static ref FILTER: Builder<'static> = { - let mut builder = Builder::new(); - builder.link_rel(Some("noopener noreferrer nofollow")); - builder.add_generic_attributes(iter::once("class")); - builder.attribute_filter(|_, attribute, value| { - if attribute == "class" { - Some( - value - .split_ascii_whitespace() - .filter(|value| value.starts_with("language-")) - .join(" ") - .into(), - ) - } else { - Some(value.into()) - } - }); - builder - }; - } + static FILTER: Lazy> = Lazy::new(|| { + let mut builder = Builder::new(); + builder.link_rel(Some("noopener noreferrer nofollow")); + builder.add_generic_attributes(iter::once("class")); + builder.attribute_filter(|_, attribute, value| { + if attribute == "class" { + Some( + value + .split_ascii_whitespace() + .filter(|value| value.starts_with("language-")) + .join(" ") + .into(), + ) + } else { + Some(value.into()) + } + }); + builder + }); let mut output = String::new(); let options = Options::ENABLE_TABLES | Options::ENABLE_STRIKETHROUGH; pulldown_cmark::html::push_html(&mut output, Parser::new_ext(markdown, options)); diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 559ca2a..fa3ff0e 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -213,7 +213,7 @@ mod test { use crate::migration; use diesel::r2d2::{ConnectionManager, CustomizeConnection, Pool}; use diesel::Connection; - use lazy_static::lazy_static; + use once_cell::sync::Lazy; use scraper::{Html, Selector}; use serde::Deserialize; use std::env; @@ -224,20 +224,18 @@ mod test { use warp::reply::{Reply, Response}; use warp::Filter; - lazy_static! { - static ref ROUTES: BoxedFilter<(Response,)> = { - let pool = Pool::builder() - .connection_customizer(Box::new(ExecuteWithinTransaction)) - .max_size(1) - .build(ConnectionManager::new(env::var("DATABASE_URL").expect( - "Setting DATABASE_URL environment variable required to run tests", - ))) - .expect("Couldn't create a connection connection"); - diesel_migrations::run_pending_migrations(&pool.get().unwrap()).unwrap(); - migration::run(&pool.get().unwrap()).unwrap(); - routes(pool).map(Reply::into_response).boxed() - }; - } + static ROUTES: Lazy> = Lazy::new(|| { + let pool = Pool::builder() + .connection_customizer(Box::new(ExecuteWithinTransaction)) + .max_size(1) + .build(ConnectionManager::new(env::var("DATABASE_URL").expect( + "Setting DATABASE_URL environment variable required to run tests", + ))) + .expect("Couldn't create a connection connection"); + diesel_migrations::run_pending_migrations(&pool.get().unwrap()).unwrap(); + migration::run(&pool.get().unwrap()).unwrap(); + routes(pool).map(Reply::into_response).boxed() + }); #[derive(Debug)] struct ExecuteWithinTransaction; diff --git a/src/routes/run.rs b/src/routes/run.rs index 395f430..da539e3 100644 --- a/src/routes/run.rs +++ b/src/routes/run.rs @@ -3,17 +3,15 @@ use crate::Connection; use diesel::prelude::*; use futures::Future; use futures03::TryFutureExt; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use reqwest::r#async::Client; use serde::{Deserialize, Serialize}; use std::env; use tokio_executor::blocking; use warp::{Rejection, Reply}; -lazy_static! { - static ref CLIENT: Client = Client::new(); - static ref SANDBOX_URL: String = env::var("SANDBOX_URL").unwrap(); -} +static CLIENT: Lazy = Lazy::new(Client::new); +static SANDBOX_URL: Lazy = Lazy::new(|| env::var("SANDBOX_URL").unwrap()); #[derive(Deserialize)] #[serde(rename_all = "camelCase")]