Skip to content
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

lib: Use std's OnceLock instead of once_cell #312

Closed
wants to merge 2 commits into from
Closed
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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ bench-suite = ["rand"]
[dependencies]
byteorder = "^1.4.2"
internment = "0.7.0"
once_cell = "1.17"
rmp-serde = "1.1.1"
serde = { version = "^1.0.57", features = ["derive"] }
serde_json = "^1.0.57"
Expand Down
6 changes: 3 additions & 3 deletions lib/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::io::{Cursor, Error as IoError, Read, Write};
use std::sync::OnceLock;
use std::{str, u8};

use crate::errors::{ValidationError, ValidationResult};
use crate::models;

use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use once_cell::sync::Lazy;
use uuid::v1::{Context, Timestamp};
use uuid::Uuid;

const NODE_ID: [u8; 6] = [0, 0, 0, 0, 0, 0];

static CONTEXT: Lazy<Context> = Lazy::new(|| Context::new(0));
static CONTEXT: OnceLock<Context> = OnceLock::new();

/// A byte-serializable value, frequently employed in the keys of key/value
/// store.
Expand Down Expand Up @@ -130,7 +130,7 @@ pub fn read_u64<T: AsRef<[u8]>>(cursor: &mut Cursor<T>) -> u64 {
/// Generates a UUID v1. This utility method uses a shared context and node ID
/// to help ensure generated UUIDs are unique.
pub fn generate_uuid_v1() -> Uuid {
Uuid::new_v1(Timestamp::now(&*CONTEXT), &NODE_ID)
Uuid::new_v1(Timestamp::now(CONTEXT.get_or_init(|| Context::new(0))), &NODE_ID)
}

/// Gets the next UUID that would occur after the given one.
Expand Down