Skip to content

Commit 39522ef

Browse files
committed
refactor: replace lazy_static with LazyLock in server_core and remove unused dependency; "fix" clippy warning
1 parent d554414 commit 39522ef

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ repository = "https://github.com/Strawberry-Foundations/strawberry-chat"
1313
libstrawberry = { version = "1.4.0", features = ["stbchat"] }
1414
tokio = { version = "1.47.1", features = ["full"] }
1515
futures = "0.3.31"
16-
lazy_static = "1.5.0"
1716
serde = { version = "1.0.219", features = ["derive"] }
1817
serde_yaml = "0.9.34-deprecated"
1918
serde_json = "1.0.143"

src/system_core/register.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::security::verification::MessageAction;
1616
use crate::system_core::log::log_parser;
1717
use crate::utilities::is_valid_username;
1818

19+
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)]
1920
pub async fn client_register(
2021
username: String,
2122
password: String,

src/system_core/server_core.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! This handles communication between clients and the server
22
33
use std::net::SocketAddr;
4+
use std::sync::LazyLock;
45
use std::time::Duration;
56

67
use tokio::sync::mpsc::{channel, Receiver, Sender};
@@ -9,7 +10,6 @@ use tokio::time::sleep;
910

1011
use libstrawberry::stbchat::object::User;
1112
use libstrawberry::string::escape_ansi;
12-
use lazy_static::lazy_static;
1313

1414
use crate::system_core::commands::run_command;
1515
use crate::system_core::internals::{MessageToClient, MessageToServer};
@@ -140,6 +140,7 @@ pub async fn send_to_all(what: MessageToClient, authed_only: bool) {
140140
}
141141
}
142142

143+
#[allow(clippy::cognitive_complexity)]
143144
pub async fn core_thread(watchdog_tx: Sender<()>) {
144145
RUNTIME_LOGGER.info(format!("Starting core thread ({})", CORE_VERSION.clone()));
145146

@@ -305,8 +306,6 @@ fn send_to_hook_sync(who: User, what: Event) -> bool {
305306
})
306307
}
307308

308-
lazy_static! {
309-
pub static ref CLIENTS: RwLock<Vec<Connection>> = RwLock::new(Vec::new());
310-
static ref EVENT_HOOKS: RwLock<Vec<EventHook>> = RwLock::new(Vec::new());
311-
pub static ref STATUS: RwLock<UserStatus> = RwLock::new(UserStatus::new());
312-
}
309+
pub static CLIENTS: LazyLock<RwLock<Vec<Connection>>> = LazyLock::new(|| RwLock::new(Vec::new()));
310+
static EVENT_HOOKS: LazyLock<RwLock<Vec<EventHook>>> = LazyLock::new(|| RwLock::new(Vec::new()));
311+
pub static STATUS: LazyLock<RwLock<UserStatus>> = LazyLock::new(|| RwLock::new(UserStatus::new()));

0 commit comments

Comments
 (0)