Skip to content

Commit

Permalink
replace once_cell with std:;sync::LazyLock
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Nov 27, 2024
1 parent dfdc314 commit 0817382
Show file tree
Hide file tree
Showing 23 changed files with 989 additions and 978 deletions.
7 changes: 0 additions & 7 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ minecraft_folder_path = "0.1.2"
nohash-hasher = "0.2.0"
num-bigint = "0.4.6"
num-traits = "0.2.19"
once_cell = "1.20.2"
parking_lot = "0.12.3"
priority-queue = "2.1.1"
proc-macro2 = "1.0.92"
Expand Down
2 changes: 0 additions & 2 deletions azalea-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ azalea-crypto = { path = "../azalea-crypto", version = "0.10.0" }
base64 = { workspace = true }
chrono = { workspace = true, features = ["serde"] }
md-5 = { workspace = true }
#num-bigint = { workspace = true }
once_cell = { workspace = true }
reqwest = { workspace = true, features = ["json", "rustls-tls"] }
rsa = { workspace = true }
serde = { workspace = true, features = ["derive"] }
Expand Down
5 changes: 3 additions & 2 deletions azalea-auth/src/sessionserver.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Tell Mojang you're joining a multiplayer server.
use once_cell::sync::Lazy;
use std::sync::LazyLock;

use reqwest::StatusCode;
use serde::Deserialize;
use serde_json::json;
Expand Down Expand Up @@ -49,7 +50,7 @@ pub struct ForbiddenError {
pub path: String,
}

static REQWEST_CLIENT: Lazy<reqwest::Client> = Lazy::new(reqwest::Client::new);
static REQWEST_CLIENT: LazyLock<reqwest::Client> = LazyLock::new(reqwest::Client::new);

/// Tell Mojang's servers that you are going to join a multiplayer server,
/// which is required to join online-mode servers. The server ID is an empty
Expand Down
5 changes: 3 additions & 2 deletions azalea-chat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ azalea-buf = ["dep:azalea-buf", "simdnbt"]
numbers = ["dep:azalea-registry", "dep:simdnbt"]

[dependencies]
azalea-buf = { path = "../azalea-buf", features = ["serde_json"], version = "0.10.0", optional = true }
azalea-buf = { path = "../azalea-buf", features = [
"serde_json",
], version = "0.10.0", optional = true }
azalea-language = { path = "../azalea-language", version = "0.10.0" }
azalea-registry = { path = "../azalea-registry", version = "0.10.0", optional = true }
once_cell = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
simdnbt = { workspace = true, optional = true }
Expand Down
5 changes: 2 additions & 3 deletions azalea-chat/src/component.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::fmt::Display;
use std::{fmt::Display, sync::LazyLock};

#[cfg(feature = "azalea-buf")]
use azalea_buf::{BufReadError, McBufReadable, McBufWritable};
use once_cell::sync::Lazy;
use serde::{de, Deserialize, Deserializer, Serialize};
#[cfg(feature = "simdnbt")]
use simdnbt::{Deserialize as _, FromNbtTag as _, Serialize as _};
Expand All @@ -23,7 +22,7 @@ pub enum FormattedText {
Translatable(TranslatableComponent),
}

pub static DEFAULT_STYLE: Lazy<Style> = Lazy::new(|| Style {
pub static DEFAULT_STYLE: LazyLock<Style> = LazyLock::new(|| Style {
color: Some(ChatFormatting::White.try_into().unwrap()),
..Style::default()
});
Expand Down
9 changes: 4 additions & 5 deletions azalea-chat/src/style.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::{collections::HashMap, fmt};
use std::{collections::HashMap, fmt, sync::LazyLock};

#[cfg(feature = "azalea-buf")]
use azalea_buf::McBuf;
use once_cell::sync::Lazy;
use serde::{ser::SerializeStruct, Serialize, Serializer};
use serde_json::Value;
#[cfg(feature = "simdnbt")]
Expand Down Expand Up @@ -57,8 +56,8 @@ impl TextColor {
}
}

static LEGACY_FORMAT_TO_COLOR: Lazy<HashMap<&'static ChatFormatting, TextColor>> =
Lazy::new(|| {
static LEGACY_FORMAT_TO_COLOR: LazyLock<HashMap<&'static ChatFormatting, TextColor>> =
LazyLock::new(|| {
let mut legacy_format_to_color = HashMap::new();
for formatter in &ChatFormatting::FORMATTERS {
if !formatter.is_format() && *formatter != ChatFormatting::Reset {
Expand All @@ -73,7 +72,7 @@ static LEGACY_FORMAT_TO_COLOR: Lazy<HashMap<&'static ChatFormatting, TextColor>>
}
legacy_format_to_color
});
static NAMED_COLORS: Lazy<HashMap<String, TextColor>> = Lazy::new(|| {
static NAMED_COLORS: LazyLock<HashMap<String, TextColor>> = LazyLock::new(|| {
let mut named_colors = HashMap::new();
for color in LEGACY_FORMAT_TO_COLOR.values() {
named_colors.insert(color.name.clone().unwrap(), color.clone());
Expand Down
6 changes: 0 additions & 6 deletions azalea-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ version = "0.10.3+mc1.21.1"

[dependencies]
anyhow = { workspace = true }
#async-trait = { workspace = true }
azalea-auth = { path = "../azalea-auth", version = "0.10.0" }
azalea-block = { path = "../azalea-block", version = "0.10.0" }
azalea-buf = { path = "../azalea-buf", version = "0.10.0" }
Expand All @@ -29,15 +28,10 @@ bevy_log = { workspace = true, optional = true }
bevy_tasks = { workspace = true }
bevy_time = { workspace = true }
derive_more = { workspace = true, features = ["deref", "deref_mut"] }
#futures = { workspace = true }
minecraft_folder_path = { workspace = true }
#nohash-hasher = { workspace = true }
once_cell = { workspace = true }
parking_lot = { workspace = true, features = ["deadlock_detection"] }
regex = { workspace = true }
reqwest = { workspace = true }
#serde = { workspace = true }
#serde_json = { workspace = true }
simdnbt = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["sync"] }
Expand Down
3 changes: 1 addition & 2 deletions azalea-client/src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ pub enum ChatPacket {

macro_rules! regex {
($re:literal $(,)?) => {{
static RE: once_cell::sync::OnceCell<regex::Regex> = once_cell::sync::OnceCell::new();
RE.get_or_init(|| regex::Regex::new($re).unwrap())
std::sync::LazyLock::new(|| regex::Regex::new($re).unwrap())
}};
}

Expand Down
2 changes: 0 additions & 2 deletions azalea-language/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ version = "0.10.3+mc1.21.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
once_cell = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
#tokio = { workspace = true, features = ["fs"] }
8 changes: 3 additions & 5 deletions azalea-language/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#![doc = include_str!("../README.md")]

use std::collections::HashMap;
use std::{collections::HashMap, sync::LazyLock};

use once_cell::sync::Lazy;

pub static STORAGE: Lazy<HashMap<String, String>> =
Lazy::new(|| serde_json::from_str(include_str!("en_us.json")).unwrap());
pub static STORAGE: LazyLock<HashMap<String, String>> =
LazyLock::new(|| serde_json::from_str(include_str!("en_us.json")).unwrap());

pub fn get(key: &str) -> Option<&str> {
STORAGE.get(key).map(|s| s.as_str())
Expand Down
5 changes: 0 additions & 5 deletions azalea-physics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ azalea-registry = { path = "../azalea-registry", version = "0.10.0" }
azalea-world = { path = "../azalea-world", version = "0.10.0" }
bevy_app = { workspace = true }
bevy_ecs = { workspace = true }
#nohash-hasher = { workspace = true }
once_cell = { workspace = true }
parking_lot = { workspace = true }
#smallvec = { workspace = true }
#tracing = { workspace = true }

[dev-dependencies]
#bevy_time = { workspace = true }
uuid = { workspace = true }
Loading

0 comments on commit 0817382

Please sign in to comment.