Skip to content

Commit cf0e5a5

Browse files
committed
Replace LazyLock with OnceLock
LazyLock only stabilizes in rustc 1.80 and causes a CI test error. OnceLock is stable since 1.70 and has the required functionality. Use OnceLock instead of LazyLock.
1 parent de4ece5 commit cf0e5a5

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

bitreq/src/connection/rustls_stream.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use alloc::sync::Arc;
55
use core::convert::TryFrom;
66
use std::io::{self, Write};
77
use std::net::TcpStream;
8+
use std::sync::OnceLock;
89

910
use rustls::{self, ClientConfig, ClientConnection, RootCertStore, ServerName, StreamOwned};
1011
#[cfg(feature = "rustls-webpki")]
@@ -15,8 +16,9 @@ use crate::Error;
1516

1617
pub type SecuredStream = StreamOwned<ClientConnection, TcpStream>;
1718

18-
#[allow(clippy::incompatible_msrv)] // We only guarantee MSRV for a subset of features.
19-
static CONFIG: std::sync::LazyLock<Arc<ClientConfig>> = std::sync::LazyLock::new(|| {
19+
static CONFIG: OnceLock<Arc<ClientConfig>> = OnceLock::new();
20+
21+
fn build_client_config() -> Arc<ClientConfig> {
2022
let mut root_certificates = RootCertStore::empty();
2123

2224
// Try to load native certs
@@ -44,7 +46,7 @@ static CONFIG: std::sync::LazyLock<Arc<ClientConfig>> = std::sync::LazyLock::new
4446
.with_root_certificates(root_certificates)
4547
.with_no_client_auth();
4648
Arc::new(config)
47-
});
49+
}
4850

4951
pub fn create_secured_stream(conn: &Connection) -> Result<HttpStream, Error> {
5052
// Rustls setup
@@ -54,8 +56,8 @@ pub fn create_secured_stream(conn: &Connection) -> Result<HttpStream, Error> {
5456
Ok(result) => result,
5557
Err(err) => return Err(Error::IoError(io::Error::new(io::ErrorKind::Other, err))),
5658
};
57-
let sess =
58-
ClientConnection::new(CONFIG.clone(), dns_name).map_err(Error::RustlsCreateConnection)?;
59+
let sess = ClientConnection::new(CONFIG.get_or_init(build_client_config).clone(), dns_name)
60+
.map_err(Error::RustlsCreateConnection)?;
5961

6062
// Connect
6163
#[cfg(feature = "log")]

0 commit comments

Comments
 (0)