Remove direct dependency on Lazy Static

This commit is contained in:
Joakim Soderlund 2024-09-04 19:19:03 +02:00
parent 3489f47ee9
commit 6c5ee17456
4 changed files with 37 additions and 33 deletions

45
Cargo.lock generated
View file

@ -3,10 +3,10 @@
version = 3 version = 3
[[package]] [[package]]
name = "adler" name = "adler2"
version = "1.0.2" version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
@ -64,9 +64,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.1.13" version = "1.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48" checksum = "e9d013ecb737093c0e86b151a7b837993cf9ec6c502946cfb44bedc392421e0b"
dependencies = [ dependencies = [
"shlex", "shlex",
] ]
@ -197,7 +197,6 @@ version = "0.1.0"
dependencies = [ dependencies = [
"chrono", "chrono",
"hex", "hex",
"lazy_static",
"rayon", "rayon",
"serde", "serde",
"serde_json", "serde_json",
@ -228,9 +227,9 @@ dependencies = [
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.0.31" version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f211bbe8e69bbd0cfdea405084f128ae8b4aaa6b0b522fc8f2b009084797920" checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253"
dependencies = [ dependencies = [
"crc32fast", "crc32fast",
"miniz_oxide", "miniz_oxide",
@ -288,9 +287,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.157" version = "0.2.158"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "374af5f94e54fa97cf75e945cce8a6b201e88a1a07e688b47dfd2a59c66dbd86" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
[[package]] [[package]]
name = "log" name = "log"
@ -312,11 +311,11 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.7.4" version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1"
dependencies = [ dependencies = [
"adler", "adler2",
] ]
[[package]] [[package]]
@ -367,9 +366,9 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.36" version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@ -450,18 +449,18 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.208" version = "1.0.209"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.208" version = "1.0.209"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -470,9 +469,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.125" version = "1.0.127"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83c8e735a073ccf5be70aa8066aa984eaf2fa000db6c8d0100ae605b366d31ed" checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad"
dependencies = [ dependencies = [
"itoa", "itoa",
"memchr", "memchr",
@ -488,9 +487,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.75" version = "2.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6af063034fc1935ede7be0122941bafa9bacb949334d090b77ca98b5817c7d9" checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View file

@ -24,9 +24,6 @@ features = ["serde"]
[dependencies.hex] [dependencies.hex]
version = "*" version = "*"
[dependencies.lazy_static]
version = "*"
[dependencies.rayon] [dependencies.rayon]
version = "*" version = "*"

View file

@ -3,6 +3,7 @@
use std::collections::HashSet; use std::collections::HashSet;
use std::hash::Hash; use std::hash::Hash;
use std::sync::Arc; use std::sync::Arc;
use std::sync::LazyLock;
use std::sync::RwLock; use std::sync::RwLock;
pub struct Interner<T>(RwLock<HashSet<Arc<T>>>); pub struct Interner<T>(RwLock<HashSet<Arc<T>>>);
@ -11,8 +12,8 @@ impl<T> Interner<T>
where where
T: Eq + Hash, T: Eq + Hash,
{ {
pub fn new() -> Self { pub const fn r#static() -> LazyLock<Self> {
Self(RwLock::new(HashSet::new())) LazyLock::new(Self::default)
} }
fn get(&self, value: &T) -> Option<Arc<T>> { fn get(&self, value: &T) -> Option<Arc<T>> {
@ -41,3 +42,12 @@ where
self.get(&value).unwrap_or_else(|| self.set(value)) self.get(&value).unwrap_or_else(|| self.set(value))
} }
} }
impl<T> Default for Interner<T>
where
T: Eq + Hash,
{
fn default() -> Self {
Self(Default::default())
}
}

View file

@ -1,9 +1,9 @@
//! Story meta. //! Story meta.
use std::sync::Arc; use std::sync::Arc;
use std::sync::LazyLock;
use chrono::prelude::*; use chrono::prelude::*;
use lazy_static::lazy_static;
use serde::de::Error; use serde::de::Error;
use serde::Deserialize; use serde::Deserialize;
use serde::Deserializer; use serde::Deserializer;
@ -11,10 +11,8 @@ use serde_json::Value;
use super::interner::Interner; use super::interner::Interner;
lazy_static! { pub(crate) static AUTHORS: LazyLock<Interner<Author>> = Interner::r#static();
pub(crate) static ref AUTHORS: Interner<Author> = Interner::new(); pub(crate) static TAGS: LazyLock<Interner<Tag>> = Interner::r#static();
pub(crate) static ref TAGS: Interner<Tag> = Interner::new();
}
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]