Skip to content

Commit b637094

Browse files
authored
move lazy_static to once_cell (#416)
1 parent 54eb635 commit b637094

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ serde_json = { version = "1.0", features = ["preserve_order"] }
6161
indexmap = "1.6.2"
6262
hex = "0.4.2"
6363
base64 = "0.13.0"
64-
lazy_static = "1.4.0"
64+
once_cell = "1.5.1"
6565
uuid-0_8 = { package = "uuid", version = "0.8.1", features = ["serde", "v4"], optional = true }
6666
uuid = { version = "1.1.2", features = ["serde", "v4"] }
6767
serde_bytes = "0.11.5"

src/oid.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ use std::{
1313
use std::{convert::TryInto, time::SystemTime};
1414

1515
use hex::{self, FromHexError};
16+
use once_cell::sync::Lazy;
1617
use rand::{thread_rng, Rng};
1718

18-
use lazy_static::lazy_static;
19-
2019
const TIMESTAMP_SIZE: usize = 4;
2120
const PROCESS_ID_SIZE: usize = 5;
2221
const COUNTER_SIZE: usize = 3;
@@ -27,9 +26,8 @@ const COUNTER_OFFSET: usize = PROCESS_ID_OFFSET + PROCESS_ID_SIZE;
2726

2827
const MAX_U24: usize = 0xFF_FFFF;
2928

30-
lazy_static! {
31-
static ref OID_COUNTER: AtomicUsize = AtomicUsize::new(thread_rng().gen_range(0..=MAX_U24));
32-
}
29+
static OID_COUNTER: Lazy<AtomicUsize> =
30+
Lazy::new(|| AtomicUsize::new(thread_rng().gen_range(0..=MAX_U24)));
3331

3432
/// Errors that can occur during [`ObjectId`] construction and generation.
3533
#[derive(Clone, Debug)]
@@ -255,9 +253,7 @@ impl ObjectId {
255253

256254
/// Generate a random 5-byte array.
257255
fn gen_process_id() -> [u8; 5] {
258-
lazy_static! {
259-
static ref BUF: [u8; 5] = thread_rng().gen();
260-
}
256+
static BUF: Lazy<[u8; 5]> = Lazy::new(|| thread_rng().gen());
261257

262258
*BUF
263259
}

src/tests/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ mod modules;
44
mod serde;
55
mod spec;
66

7-
use lazy_static::lazy_static;
87
use modules::TestLock;
8+
use once_cell::sync::Lazy;
99

10-
lazy_static! {
11-
pub(crate) static ref LOCK: TestLock = TestLock::new();
12-
}
10+
pub(crate) static LOCK: Lazy<TestLock> = Lazy::new(TestLock::new);

0 commit comments

Comments
 (0)