replace once_cell with std:;sync::LazyLock

This commit is contained in:
mat 2024-11-27 10:26:40 +00:00
parent dfdc3144b6
commit 0817382098
23 changed files with 989 additions and 978 deletions

7
Cargo.lock generated
View file

@ -237,7 +237,6 @@ dependencies = [
"chrono",
"env_logger",
"md-5",
"once_cell",
"reqwest",
"rsa",
"serde",
@ -306,7 +305,6 @@ dependencies = [
"azalea-buf",
"azalea-language",
"azalea-registry",
"once_cell",
"serde",
"serde_json",
"simdnbt",
@ -337,7 +335,6 @@ dependencies = [
"bevy_time",
"derive_more",
"minecraft_folder_path",
"once_cell",
"parking_lot",
"regex",
"reqwest",
@ -428,7 +425,6 @@ dependencies = [
name = "azalea-language"
version = "0.10.3+mc1.21.1"
dependencies = [
"once_cell",
"serde",
"serde_json",
]
@ -445,7 +441,6 @@ dependencies = [
"azalea-world",
"bevy_app",
"bevy_ecs",
"once_cell",
"parking_lot",
"uuid",
]
@ -474,7 +469,6 @@ dependencies = [
"futures",
"futures-lite",
"log",
"once_cell",
"serde",
"serde_json",
"simdnbt",
@ -503,7 +497,6 @@ version = "0.10.3+mc1.21.1"
dependencies = [
"azalea-buf",
"azalea-registry-macros",
"once_cell",
"serde",
"simdnbt",
]

View file

@ -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"

View file

@ -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"] }

View file

@ -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;
@ -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

View file

@ -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 }

View file

@ -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 _};
@ -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()
});

View file

@ -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")]
@ -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 {
@ -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());

View file

@ -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" }
@ -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"] }

View file

@ -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())
}};
}

View file

@ -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"] }

View file

@ -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())

View file

@ -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 }

File diff suppressed because it is too large Load diff

View file

@ -12,10 +12,17 @@ version = "0.10.3+mc1.21.1"
async-recursion = { workspace = true }
azalea-auth = { path = "../azalea-auth", version = "0.10.0" }
azalea-block = { path = "../azalea-block", default-features = false, version = "0.10.0" }
azalea-brigadier = { path = "../azalea-brigadier", version = "0.10.0", features = ["azalea-buf"] }
azalea-brigadier = { path = "../azalea-brigadier", version = "0.10.0", features = [
"azalea-buf",
] }
azalea-buf = { path = "../azalea-buf", version = "0.10.0" }
azalea-chat = { path = "../azalea-chat", version = "0.10.0", features = ["numbers", "azalea-buf"] }
azalea-core = { path = "../azalea-core", optional = true, version = "0.10.0", features = ["serde"] }
azalea-chat = { path = "../azalea-chat", version = "0.10.0", features = [
"numbers",
"azalea-buf",
] }
azalea-core = { path = "../azalea-core", optional = true, version = "0.10.0", features = [
"serde",
] }
azalea-crypto = { path = "../azalea-crypto", version = "0.10.0" }
azalea-entity = { version = "0.10.0", path = "../azalea-entity" }
azalea-inventory = { version = "0.10.0", path = "../azalea-inventory" }
@ -48,6 +55,5 @@ packets = ["connecting", "dep:azalea-core"]
[dev-dependencies]
anyhow = { workspace = true }
once_cell = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }

View file

@ -1,7 +1,7 @@
//! A "simple" server that gets login information and proxies connections.
//! After login all connections are encrypted and Azalea cannot read them.
use std::error::Error;
use std::{error::Error, sync::LazyLock};
use azalea_protocol::{
connect::Connection,
@ -23,7 +23,6 @@ use azalea_protocol::{
read::ReadPacketError,
};
use futures::FutureExt;
use once_cell::sync::Lazy;
use tokio::{
io::{self, AsyncWriteExt},
net::{TcpListener, TcpStream},
@ -37,9 +36,9 @@ const PROXY_ADDR: &str = "127.0.0.1:25565";
const PROXY_DESC: &str = "An Azalea Minecraft Proxy";
// String must be formatted like "data:image/png;base64,<data>"
static PROXY_FAVICON: Lazy<Option<String>> = Lazy::new(|| None);
static PROXY_FAVICON: LazyLock<Option<String>> = LazyLock::new(|| None);
static PROXY_VERSION: Lazy<Version> = Lazy::new(|| Version {
static PROXY_VERSION: LazyLock<Version> = LazyLock::new(|| Version {
name: "1.19.3".to_string(),
protocol: PROTOCOL_VERSION,
});

View file

@ -11,7 +11,6 @@ version = "0.10.3+mc1.21.1"
[dependencies]
azalea-buf = { path = "../azalea-buf", version = "0.10.0" }
azalea-registry-macros = { path = "./azalea-registry-macros", version = "0.10.0" }
once_cell = { workspace = true }
serde = { workspace = true, optional = true }
simdnbt = { workspace = true }

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,11 @@
// This file was generated by codegen/lib/code/tags.py, don't edit it manually!
use std::collections::HashSet;
use once_cell::sync::Lazy;
use std::sync::LazyLock;
use crate::Fluid;
pub static LAVA: Lazy<HashSet<Fluid>> =
Lazy::new(|| HashSet::from_iter(vec![Fluid::Lava, Fluid::FlowingLava]));
pub static WATER: Lazy<HashSet<Fluid>> =
Lazy::new(|| HashSet::from_iter(vec![Fluid::Water, Fluid::FlowingWater]));
pub static LAVA: LazyLock<HashSet<Fluid>> =
LazyLock::new(|| HashSet::from_iter(vec![Fluid::Lava, Fluid::FlowingLava]));
pub static WATER: LazyLock<HashSet<Fluid>> =
LazyLock::new(|| HashSet::from_iter(vec![Fluid::Water, Fluid::FlowingWater]));

File diff suppressed because it is too large Load diff

View file

@ -11,20 +11,18 @@ version = "0.10.3+mc1.21.1"
[dependencies]
azalea-block = { path = "../azalea-block", default-features = false, version = "0.10.0" }
azalea-buf = { path = "../azalea-buf", version = "0.10.0" }
azalea-core = { path = "../azalea-core", version = "0.10.0", features = ["bevy_ecs"] }
azalea-core = { path = "../azalea-core", version = "0.10.0", features = [
"bevy_ecs",
] }
azalea-registry = { path = "../azalea-registry", version = "0.10.0" }
bevy_ecs = { workspace = true }
derive_more = { workspace = true, features = ["deref", "deref_mut"] }
nohash-hasher = { workspace = true }
#once_cell = { workspace = true }
parking_lot = { workspace = true }
rustc-hash = { workspace = true }
#serde = { workspace = true }
#serde_json = { workspace = true }
simdnbt = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
#uuid = { workspace = true }
[dev-dependencies]
azalea-client = { path = "../azalea-client" }

View file

@ -1,10 +1,11 @@
//! The goals that a pathfinder can try to reach.
use std::f32::consts::SQRT_2;
use azalea_core::position::{BlockPos, Vec3};
use azalea_world::ChunkStorage;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::f32::consts::SQRT_2;
use super::costs::{COST_HEURISTIC, FALL_N_BLOCKS_COST, JUMP_ONE_BLOCK_COST};

View file

@ -71,7 +71,7 @@ def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report,
generated_shape_code += generate_code_for_shape(shape_id, shape)
# static SHAPES_MAP: [&Lazy<VoxelShape>; 26644] = [&SHAPE0, &SHAPE1, &SHAPE1, ...]
# static SHAPES_MAP: [&LazyLock<VoxelShape>; 26644] = [&SHAPE0, &SHAPE1, &SHAPE1, ...]
empty_shapes = []
full_shapes = []
@ -92,7 +92,7 @@ def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report,
block_state_ids_to_shape_ids.append((block_state_id, shape_id))
generated_map_code = f'static SHAPES_MAP: [&Lazy<VoxelShape>; {len(block_state_ids_to_shape_ids)}] = ['
generated_map_code = f'static SHAPES_MAP: [&LazyLock<VoxelShape>; {len(block_state_ids_to_shape_ids)}] = ['
block_state_ids_to_shape_ids = sorted(block_state_ids_to_shape_ids, key=lambda x: x[0])
@ -118,7 +118,7 @@ def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report,
use super::VoxelShape;
use crate::collision::{{self, Shapes}};
use azalea_block::*;
use once_cell::sync::Lazy;
use std::sync::LazyLock;
pub trait BlockWithShape {{
fn shape(&self) -> &'static VoxelShape;
@ -156,7 +156,7 @@ def generate_code_for_shape(shape_id: str, parts: list[list[float]]):
def make_arguments(part: list[float]):
return ', '.join(map(lambda n: str(n).rstrip('0'), part))
code = ''
code += f'static SHAPE{shape_id}: Lazy<VoxelShape> = Lazy::new(|| {{'
code += f'static SHAPE{shape_id}: LazyLock<VoxelShape> = LazyLock::new(|| {{'
steps = []
if parts == ():
steps.append('collision::EMPTY_SHAPE.clone()')

View file

@ -9,8 +9,7 @@ def generate_tags(registries: dict, file_name: str, struct_name: str):
generated = f'''// This file was generated by codegen/lib/code/tags.py, don't edit it manually!
use std::collections::HashSet;
use once_cell::sync::Lazy;
use std::sync::LazyLock;
use crate::{struct_name};
@ -19,7 +18,7 @@ use crate::{struct_name};
for tag_name, tag in sorted(registries.items(), key=lambda x: x[0]):
tag_name = tag_name.replace('/', '_')
static_set_name = to_snake_case(tag_name).upper()
generated += f'pub static {static_set_name}: Lazy<HashSet<{struct_name}>> = Lazy::new(|| HashSet::from_iter(vec!['
generated += f'pub static {static_set_name}: LazyLock<HashSet<{struct_name}>> = LazyLock::new(|| HashSet::from_iter(vec!['
queue = tag['values'].copy()
while queue != []: