aboutsummaryrefslogtreecommitdiff
path: root/azalea-client
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-11-19 15:21:54 -0600
committerGitHub <noreply@github.com>2022-11-19 15:21:54 -0600
commit619984fa33aec8b9629770928c51ee81a3d3a63f (patch)
treefa6de3852d08dea6f77ba2549d98b9fcb457309a /azalea-client
parentbefa22c1f3ff0c1f0cb745b3f4e736910c053a8b (diff)
downloadazalea-drasl-619984fa33aec8b9629770928c51ee81a3d3a63f.tar.xz
Replace lazy_static with once_cell::sync::Lazy (#43)
* Remove lazy_static in azalea-chat * replace lazy_static with once_cell everywhere * fix * fix import * ignore a clippy warning in shape codegen
Diffstat (limited to 'azalea-client')
-rw-r--r--azalea-client/Cargo.toml2
-rwxr-xr-xazalea-client/src/chat.rs15
2 files changed, 9 insertions, 8 deletions
diff --git a/azalea-client/Cargo.toml b/azalea-client/Cargo.toml
index 3f67dd99..fc3f2061 100644
--- a/azalea-client/Cargo.toml
+++ b/azalea-client/Cargo.toml
@@ -19,9 +19,9 @@ azalea-crypto = {path = "../azalea-crypto", version = "0.3.0"}
azalea-physics = {path = "../azalea-physics", version = "0.3.0"}
azalea-protocol = {path = "../azalea-protocol", version = "0.3.0"}
azalea-world = {path = "../azalea-world", version = "0.3.0"}
-lazy_static = "1.4.0"
log = "0.4.17"
nohash-hasher = "0.2.0"
+once_cell = "1.16.0"
parking_lot = {version = "^0.12.1", features = ["deadlock_detection"]}
regex = "1.7.0"
thiserror = "^1.0.34"
diff --git a/azalea-client/src/chat.rs b/azalea-client/src/chat.rs
index 3a0efa95..01236630 100755
--- a/azalea-client/src/chat.rs
+++ b/azalea-client/src/chat.rs
@@ -9,8 +9,6 @@ use azalea_protocol::packets::game::{
serverbound_chat_command_packet::ServerboundChatCommandPacket,
serverbound_chat_packet::ServerboundChatPacket,
};
-use lazy_static::lazy_static;
-use regex::Regex;
use std::time::{SystemTime, UNIX_EPOCH};
/// A chat packet, either a system message or a chat message.
@@ -20,6 +18,13 @@ pub enum ChatPacket {
Player(Box<ClientboundPlayerChatPacket>),
}
+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())
+ }};
+}
+
impl ChatPacket {
/// Get the message shown in chat for this packet.
pub fn message(&self) -> Component {
@@ -49,11 +54,7 @@ impl ChatPacket {
}
// It's a system message, so we'll have to match the content
// with regex
- lazy_static! {
- static ref ANGLE_BRACKETS_RE: Regex =
- Regex::new("^<([a-zA-Z_0-9]{1,16})> (.+)$").unwrap();
- }
- if let Some(m) = ANGLE_BRACKETS_RE.captures(&message) {
+ if let Some(m) = regex!("^<([a-zA-Z_0-9]{1,16})> (.+)$").captures(&message) {
return (Some(m[1].to_string()), m[2].to_string());
}