Skip to content

Commit 74e7062

Browse files
authored
Migrate to once_cell. (#1565)
1 parent b72a385 commit 74e7062

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ futures-util = { version = "0.3.0", default-features = false }
9898
http-body = "0.4.0"
9999
hyper = { version = "0.14.18", default-features = false, features = ["tcp", "http1", "http2", "client", "runtime"] }
100100
h2 = "0.3.10"
101-
lazy_static = "1.4"
101+
once_cell = "1"
102102
log = "0.4"
103103
mime = "0.3.16"
104104
percent-encoding = "2.1"

src/dns.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::task::{self, Poll};
77

88
use hyper::client::connect::dns as hyper_dns;
99
use hyper::service::Service;
10+
use once_cell::sync::Lazy;
1011
use tokio::sync::Mutex;
1112
use trust_dns_resolver::{
1213
config::{ResolverConfig, ResolverOpts},
@@ -18,10 +19,8 @@ use crate::error::BoxError;
1819

1920
type SharedResolver = Arc<AsyncResolver<TokioConnection, TokioConnectionProvider>>;
2021

21-
lazy_static! {
22-
static ref SYSTEM_CONF: io::Result<(ResolverConfig, ResolverOpts)> =
23-
system_conf::read_system_conf().map_err(io::Error::from);
24-
}
22+
static SYSTEM_CONF: Lazy<io::Result<(ResolverConfig, ResolverOpts)>> =
23+
Lazy::new(|| system_conf::read_system_conf().map_err(io::Error::from));
2524

2625
#[derive(Clone)]
2726
pub(crate) struct TrustDnsResolver {

src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,6 @@ if_hyper! {
289289
#[macro_use]
290290
extern crate doc_comment;
291291

292-
#[macro_use]
293-
extern crate lazy_static;
294-
295292
#[cfg(test)]
296293
doctest!("../README.md");
297294

src/proxy.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::into_url::{IntoUrl, IntoUrlSealed};
77
use crate::Url;
88
use http::{header::HeaderValue, Uri};
99
use ipnet::IpNet;
10+
use once_cell::sync::Lazy;
1011
use percent_encoding::percent_decode;
1112
use std::collections::HashMap;
1213
use std::env;
@@ -755,9 +756,8 @@ impl Dst for Uri {
755756
}
756757
}
757758

758-
lazy_static! {
759-
static ref SYS_PROXIES: Arc<SystemProxyMap> = Arc::new(get_sys_proxies(get_from_registry()));
760-
}
759+
static SYS_PROXIES: Lazy<Arc<SystemProxyMap>> =
760+
Lazy::new(|| Arc::new(get_sys_proxies(get_from_registry())));
761761

762762
/// Get system proxies information.
763763
///
@@ -934,7 +934,7 @@ fn parse_registry_values(registry_values: RegistryProxyValues) -> SystemProxyMap
934934
#[cfg(test)]
935935
mod tests {
936936
use super::*;
937-
use lazy_static::lazy_static;
937+
use once_cell::sync::Lazy;
938938
use std::sync::Mutex;
939939

940940
impl Dst for Url {
@@ -1074,9 +1074,7 @@ mod tests {
10741074
// Smallest possible content for a mutex
10751075
struct MutexInner;
10761076

1077-
lazy_static! {
1078-
static ref ENVLOCK: Mutex<MutexInner> = Mutex::new(MutexInner);
1079-
}
1077+
static ENVLOCK: Lazy<Mutex<MutexInner>> = Lazy::new(|| Mutex::new(MutexInner));
10801078

10811079
#[test]
10821080
fn test_get_sys_proxies_parsing() {

0 commit comments

Comments
 (0)