Skip to content

Commit abfe2f7

Browse files
noxinikulin
authored andcommitted
Switch boring from lazy_static to once_cell
1 parent af5bb39 commit abfe2f7

File tree

5 files changed

+13
-19
lines changed

5 files changed

+13
-19
lines changed

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ fs_extra = "1.3.0"
2323
fslock = "0.2"
2424
bitflags = "1.0"
2525
foreign-types = "0.5"
26-
lazy_static = "1"
2726
libc = "0.2"
2827
hex = "0.4"
2928
rusty-hook = "^0.11"

boring/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pq-experimental = ["boring-sys/pq-experimental"]
3131
[dependencies]
3232
bitflags = { workspace = true }
3333
foreign-types = { workspace = true }
34-
lazy_static = { workspace = true }
34+
once_cell = { workspace = true }
3535
libc = { workspace = true }
3636
boring-sys = { workspace = true }
3737

boring/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@
8181
extern crate bitflags;
8282
#[macro_use]
8383
extern crate foreign_types;
84-
#[macro_use]
85-
extern crate lazy_static;
8684
extern crate boring_sys as ffi;
8785
extern crate libc;
8886

boring/src/ssl/callbacks.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ where
6666

6767
let ssl = unsafe { SslRef::from_ptr_mut(ssl_ptr) };
6868

69-
let hint = if !hint.is_null() {
70-
Some(unsafe { CStr::from_ptr(hint) }.to_bytes())
71-
} else {
69+
let hint = if hint.is_null() {
7270
None
71+
} else {
72+
Some(unsafe { CStr::from_ptr(hint) }.to_bytes())
7373
};
7474

7575
// Give the callback mutable slices into which it can write the identity and psk.
@@ -107,10 +107,10 @@ where
107107

108108
let ssl = unsafe { SslRef::from_ptr_mut(ssl) };
109109

110-
let identity = if !identity.is_null() {
111-
Some(unsafe { CStr::from_ptr(identity) }.to_bytes())
112-
} else {
110+
let identity = if identity.is_null() {
113111
None
112+
} else {
113+
Some(unsafe { CStr::from_ptr(identity) }.to_bytes())
114114
};
115115

116116
// Give the callback mutable slices into which it can write the psk.

boring/src/ssl/mod.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
use crate::ffi;
6161
use foreign_types::{ForeignType, ForeignTypeRef, Opaque};
6262
use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_void};
63+
use once_cell::sync::Lazy;
6364
use std::any::TypeId;
6465
use std::cmp;
6566
use std::collections::HashMap;
@@ -413,16 +414,12 @@ impl NameType {
413414
}
414415
}
415416

416-
lazy_static! {
417-
static ref INDEXES: Mutex<HashMap<TypeId, c_int>> = Mutex::new(HashMap::new());
418-
static ref SSL_INDEXES: Mutex<HashMap<TypeId, c_int>> = Mutex::new(HashMap::new());
419-
static ref SESSION_CTX_INDEX: Index<Ssl, SslContext> = Ssl::new_ex_index().unwrap();
420-
}
421-
417+
static INDEXES: Lazy<Mutex<HashMap<TypeId, c_int>>> = Lazy::new(|| Mutex::new(HashMap::new()));
418+
static SSL_INDEXES: Lazy<Mutex<HashMap<TypeId, c_int>>> = Lazy::new(|| Mutex::new(HashMap::new()));
419+
static SESSION_CTX_INDEX: Lazy<Index<Ssl, SslContext>> = Lazy::new(|| Ssl::new_ex_index().unwrap());
422420
#[cfg(feature = "rpk")]
423-
lazy_static! {
424-
static ref RPK_FLAG_INDEX: Index<SslContext, bool> = SslContext::new_ex_index().unwrap();
425-
}
421+
static RPK_FLAG_INDEX: Lazy<Index<SslContext, bool>> =
422+
Lazy::new(|| SslContext::new_ex_index().unwrap());
426423

427424
unsafe extern "C" fn free_data_box<T>(
428425
_parent: *mut c_void,

0 commit comments

Comments
 (0)