Skip to content

move lazy_static to once_cell #416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 4 additions & 8 deletions src/oid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<AtomicUsize> =
Lazy::new(|| AtomicUsize::new(thread_rng().gen_range(0..=MAX_U24)));

/// Errors that can occur during [`ObjectId`] construction and generation.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 2 additions & 4 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestLock> = Lazy::new(TestLock::new);