Skip to content

Commit

Permalink
Replace lazy_static! with once_cell Lazy (#176)
Browse files Browse the repository at this point in the history
Modern rust code bases prefer once_cell::sync::Lazy over the older
macro based lazy_static.
  • Loading branch information
algesten authored Oct 4, 2020
1 parent b58a3a5 commit 0bf9810
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
14 changes: 6 additions & 8 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Stream, Error> {
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use std::sync::Arc;

lazy_static! {
static ref TLS_CONF: Arc<rustls::ClientConfig> = {
let mut config = rustls::ClientConfig::new();
configure_certs(&mut config);
Arc::new(config)
};
}
static TLS_CONF: Lazy<Arc<rustls::ClientConfig>> = Lazy::new(|| {
let mut config = rustls::ClientConfig::new();
configure_certs(&mut config);
Arc::new(config)
});

let port = unit.url.port().unwrap_or(443);

Expand Down
8 changes: 3 additions & 5 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -19,10 +19,8 @@ mod timeout;

type RequestHandler = dyn Fn(&Unit) -> Result<Stream, Error> + Send + 'static;

lazy_static! {
pub(crate) static ref TEST_HANDLERS: Arc<Mutex<HashMap<String, Box<RequestHandler>>>> =
Arc::new(Mutex::new(HashMap::new()));
}
pub(crate) static TEST_HANDLERS: Lazy<Arc<Mutex<HashMap<String, Box<RequestHandler>>>>> =
Lazy::new(|| Arc::new(Mutex::new(HashMap::new())));

pub(crate) fn set_handler<H>(path: &str, handler: H)
where
Expand Down

0 comments on commit 0bf9810

Please sign in to comment.