Replace lazy_static! with once_cell Lazy (#176)
Modern rust code bases prefer once_cell::sync::Lazy over the older macro based lazy_static.
This commit is contained in:
@@ -27,7 +27,7 @@ socks-proxy = ["socks"]
|
|||||||
base64 = "0.13"
|
base64 = "0.13"
|
||||||
chunked_transfer = "1.2.0"
|
chunked_transfer = "1.2.0"
|
||||||
cookie = { version = "0.14", features = ["percent-encode"], optional = true}
|
cookie = { version = "0.14", features = ["percent-encode"], optional = true}
|
||||||
lazy_static = "1"
|
once_cell = "1"
|
||||||
qstring = "0.7"
|
qstring = "0.7"
|
||||||
url = "2"
|
url = "2"
|
||||||
socks = { version = "0.3.2", optional = true }
|
socks = { version = "0.3.2", optional = true }
|
||||||
|
|||||||
@@ -327,16 +327,14 @@ fn configure_certs(config: &mut rustls::ClientConfig) {
|
|||||||
|
|
||||||
#[cfg(all(feature = "tls", not(feature = "native-tls")))]
|
#[cfg(all(feature = "tls", not(feature = "native-tls")))]
|
||||||
pub(crate) fn connect_https(unit: &Unit, hostname: &str) -> Result<Stream, Error> {
|
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;
|
use std::sync::Arc;
|
||||||
|
|
||||||
lazy_static! {
|
static TLS_CONF: Lazy<Arc<rustls::ClientConfig>> = Lazy::new(|| {
|
||||||
static ref TLS_CONF: Arc<rustls::ClientConfig> = {
|
let mut config = rustls::ClientConfig::new();
|
||||||
let mut config = rustls::ClientConfig::new();
|
configure_certs(&mut config);
|
||||||
configure_certs(&mut config);
|
Arc::new(config)
|
||||||
Arc::new(config)
|
});
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let port = unit.url.port().unwrap_or(443);
|
let port = unit.url.port().unwrap_or(443);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::stream::Stream;
|
use crate::stream::Stream;
|
||||||
use crate::unit::Unit;
|
use crate::unit::Unit;
|
||||||
use lazy_static::lazy_static;
|
use once_cell::sync::Lazy;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::{Cursor, Write};
|
use std::io::{Cursor, Write};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
@@ -19,10 +19,8 @@ mod timeout;
|
|||||||
|
|
||||||
type RequestHandler = dyn Fn(&Unit) -> Result<Stream, Error> + Send + 'static;
|
type RequestHandler = dyn Fn(&Unit) -> Result<Stream, Error> + Send + 'static;
|
||||||
|
|
||||||
lazy_static! {
|
pub(crate) static TEST_HANDLERS: Lazy<Arc<Mutex<HashMap<String, Box<RequestHandler>>>>> =
|
||||||
pub(crate) static ref TEST_HANDLERS: Arc<Mutex<HashMap<String, Box<RequestHandler>>>> =
|
Lazy::new(|| Arc::new(Mutex::new(HashMap::new())));
|
||||||
Arc::new(Mutex::new(HashMap::new()));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn set_handler<H>(path: &str, handler: H)
|
pub(crate) fn set_handler<H>(path: &str, handler: H)
|
||||||
where
|
where
|
||||||
|
|||||||
Reference in New Issue
Block a user