diff --git a/Cargo.toml b/Cargo.toml index eb9a2a0a..fdf9b155 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,7 +61,7 @@ serde_json = { version = "1.0", features = ["preserve_order"] } indexmap = "1.6.2" hex = "0.4.2" base64 = "0.13.0" -lazy_static = "1.4.0" +once_cell = "1.5.1" uuid-0_8 = { package = "uuid", version = "0.8.1", features = ["serde", "v4"], optional = true } uuid = { version = "1.1.2", features = ["serde", "v4"] } serde_bytes = "0.11.5" diff --git a/src/oid.rs b/src/oid.rs index 263fc805..1e5f7ad5 100644 --- a/src/oid.rs +++ b/src/oid.rs @@ -13,10 +13,9 @@ use std::{ use std::{convert::TryInto, time::SystemTime}; use hex::{self, FromHexError}; +use once_cell::sync::Lazy; use rand::{thread_rng, Rng}; -use lazy_static::lazy_static; - const TIMESTAMP_SIZE: usize = 4; const PROCESS_ID_SIZE: usize = 5; const COUNTER_SIZE: usize = 3; @@ -27,9 +26,8 @@ const COUNTER_OFFSET: usize = PROCESS_ID_OFFSET + PROCESS_ID_SIZE; const MAX_U24: usize = 0xFF_FFFF; -lazy_static! { - static ref OID_COUNTER: AtomicUsize = AtomicUsize::new(thread_rng().gen_range(0..=MAX_U24)); -} +static OID_COUNTER: Lazy = + Lazy::new(|| AtomicUsize::new(thread_rng().gen_range(0..=MAX_U24))); /// Errors that can occur during [`ObjectId`] construction and generation. #[derive(Clone, Debug)] @@ -255,9 +253,7 @@ impl ObjectId { /// Generate a random 5-byte array. fn gen_process_id() -> [u8; 5] { - lazy_static! { - static ref BUF: [u8; 5] = thread_rng().gen(); - } + static BUF: Lazy<[u8; 5]> = Lazy::new(|| thread_rng().gen()); *BUF } diff --git a/src/tests/mod.rs b/src/tests/mod.rs index eccc25d9..23deeea5 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -4,9 +4,7 @@ mod modules; mod serde; mod spec; -use lazy_static::lazy_static; use modules::TestLock; +use once_cell::sync::Lazy; -lazy_static! { - pub(crate) static ref LOCK: TestLock = TestLock::new(); -} +pub(crate) static LOCK: Lazy = Lazy::new(TestLock::new);