From 0bf981031bc0f5b3ad4a6804868fda0b09ccbe84 Mon Sep 17 00:00:00 2001 From: Martin Algesten Date: Sun, 4 Oct 2020 18:35:31 +0200 Subject: [PATCH] Replace lazy_static! with once_cell Lazy (#176) Modern rust code bases prefer once_cell::sync::Lazy over the older macro based lazy_static. --- Cargo.toml | 2 +- src/stream.rs | 14 ++++++-------- src/test/mod.rs | 8 +++----- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e562bc3..d71fb83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ socks-proxy = ["socks"] base64 = "0.13" chunked_transfer = "1.2.0" cookie = { version = "0.14", features = ["percent-encode"], optional = true} -lazy_static = "1" +once_cell = "1" qstring = "0.7" url = "2" socks = { version = "0.3.2", optional = true } diff --git a/src/stream.rs b/src/stream.rs index 0697f93..84ac940 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -327,16 +327,14 @@ fn configure_certs(config: &mut rustls::ClientConfig) { #[cfg(all(feature = "tls", not(feature = "native-tls")))] pub(crate) fn connect_https(unit: &Unit, hostname: &str) -> Result { - use lazy_static::lazy_static; + use once_cell::sync::Lazy; use std::sync::Arc; - lazy_static! { - static ref TLS_CONF: Arc = { - let mut config = rustls::ClientConfig::new(); - configure_certs(&mut config); - Arc::new(config) - }; - } + static TLS_CONF: Lazy> = Lazy::new(|| { + let mut config = rustls::ClientConfig::new(); + configure_certs(&mut config); + Arc::new(config) + }); let port = unit.url.port().unwrap_or(443); diff --git a/src/test/mod.rs b/src/test/mod.rs index 801b7c9..d6f9306 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -1,7 +1,7 @@ use crate::error::Error; use crate::stream::Stream; use crate::unit::Unit; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::collections::HashMap; use std::io::{Cursor, Write}; use std::sync::{Arc, Mutex}; @@ -19,10 +19,8 @@ mod timeout; type RequestHandler = dyn Fn(&Unit) -> Result + Send + 'static; -lazy_static! { - pub(crate) static ref TEST_HANDLERS: Arc>>> = - Arc::new(Mutex::new(HashMap::new())); -} +pub(crate) static TEST_HANDLERS: Lazy>>>> = + Lazy::new(|| Arc::new(Mutex::new(HashMap::new()))); pub(crate) fn set_handler(path: &str, handler: H) where