Migrate to once_cell. (#1565)
This commit is contained in:
@@ -98,7 +98,7 @@ futures-util = { version = "0.3.0", default-features = false }
|
|||||||
http-body = "0.4.0"
|
http-body = "0.4.0"
|
||||||
hyper = { version = "0.14.18", default-features = false, features = ["tcp", "http1", "http2", "client", "runtime"] }
|
hyper = { version = "0.14.18", default-features = false, features = ["tcp", "http1", "http2", "client", "runtime"] }
|
||||||
h2 = "0.3.10"
|
h2 = "0.3.10"
|
||||||
lazy_static = "1.4"
|
once_cell = "1"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
mime = "0.3.16"
|
mime = "0.3.16"
|
||||||
percent-encoding = "2.1"
|
percent-encoding = "2.1"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use std::task::{self, Poll};
|
|||||||
|
|
||||||
use hyper::client::connect::dns as hyper_dns;
|
use hyper::client::connect::dns as hyper_dns;
|
||||||
use hyper::service::Service;
|
use hyper::service::Service;
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use trust_dns_resolver::{
|
use trust_dns_resolver::{
|
||||||
config::{ResolverConfig, ResolverOpts},
|
config::{ResolverConfig, ResolverOpts},
|
||||||
@@ -18,10 +19,8 @@ use crate::error::BoxError;
|
|||||||
|
|
||||||
type SharedResolver = Arc<AsyncResolver<TokioConnection, TokioConnectionProvider>>;
|
type SharedResolver = Arc<AsyncResolver<TokioConnection, TokioConnectionProvider>>;
|
||||||
|
|
||||||
lazy_static! {
|
static SYSTEM_CONF: Lazy<io::Result<(ResolverConfig, ResolverOpts)>> =
|
||||||
static ref SYSTEM_CONF: io::Result<(ResolverConfig, ResolverOpts)> =
|
Lazy::new(|| system_conf::read_system_conf().map_err(io::Error::from));
|
||||||
system_conf::read_system_conf().map_err(io::Error::from);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct TrustDnsResolver {
|
pub(crate) struct TrustDnsResolver {
|
||||||
|
|||||||
@@ -289,9 +289,6 @@ if_hyper! {
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate doc_comment;
|
extern crate doc_comment;
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate lazy_static;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
doctest!("../README.md");
|
doctest!("../README.md");
|
||||||
|
|
||||||
|
|||||||
12
src/proxy.rs
12
src/proxy.rs
@@ -7,6 +7,7 @@ use crate::into_url::{IntoUrl, IntoUrlSealed};
|
|||||||
use crate::Url;
|
use crate::Url;
|
||||||
use http::{header::HeaderValue, Uri};
|
use http::{header::HeaderValue, Uri};
|
||||||
use ipnet::IpNet;
|
use ipnet::IpNet;
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
use percent_encoding::percent_decode;
|
use percent_encoding::percent_decode;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
@@ -755,9 +756,8 @@ impl Dst for Uri {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
static SYS_PROXIES: Lazy<Arc<SystemProxyMap>> =
|
||||||
static ref SYS_PROXIES: Arc<SystemProxyMap> = Arc::new(get_sys_proxies(get_from_registry()));
|
Lazy::new(|| Arc::new(get_sys_proxies(get_from_registry())));
|
||||||
}
|
|
||||||
|
|
||||||
/// Get system proxies information.
|
/// Get system proxies information.
|
||||||
///
|
///
|
||||||
@@ -934,7 +934,7 @@ fn parse_registry_values(registry_values: RegistryProxyValues) -> SystemProxyMap
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use lazy_static::lazy_static;
|
use once_cell::sync::Lazy;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
impl Dst for Url {
|
impl Dst for Url {
|
||||||
@@ -1074,9 +1074,7 @@ mod tests {
|
|||||||
// Smallest possible content for a mutex
|
// Smallest possible content for a mutex
|
||||||
struct MutexInner;
|
struct MutexInner;
|
||||||
|
|
||||||
lazy_static! {
|
static ENVLOCK: Lazy<Mutex<MutexInner>> = Lazy::new(|| Mutex::new(MutexInner));
|
||||||
static ref ENVLOCK: Mutex<MutexInner> = Mutex::new(MutexInner);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_sys_proxies_parsing() {
|
fn test_get_sys_proxies_parsing() {
|
||||||
|
|||||||
Reference in New Issue
Block a user