From 9191bc41cc0a4a3b37d8c9b221fcaba050fc8b1d Mon Sep 17 00:00:00 2001 From: Rudxain <76864299+Rudxain@users.noreply.github.com> Date: Wed, 11 Mar 2026 01:41:46 -0400 Subject: [PATCH] refactor: `lazy_static` -> `LazyLock` --- Cargo.toml | 1 - src/sdl2/event.rs | 8 +++----- src/sdl2/lib.rs | 3 --- tests/events.rs | 7 ++----- 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 069438caa1..3855cb5da3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,6 @@ path = "src/sdl2/lib.rs" [dependencies] bitflags = "2.10.0" libc = "0.2.92" -lazy_static = "1.5.0" [dependencies.sdl2-sys] path = "sdl2-sys" diff --git a/src/sdl2/event.rs b/src/sdl2/event.rs index 52a823a013..88713940e0 100644 --- a/src/sdl2/event.rs +++ b/src/sdl2/event.rs @@ -9,7 +9,7 @@ use std::marker::PhantomData; use std::mem; use std::mem::transmute; use std::ptr; -use std::sync::Mutex; +use std::sync::{LazyLock, Mutex}; use libc::c_int; use libc::c_void; @@ -44,10 +44,8 @@ impl CustomEventTypeMaps { } } -lazy_static! { - static ref CUSTOM_EVENT_TYPES: Mutex = - Mutex::new(CustomEventTypeMaps::new()); -} +static CUSTOM_EVENT_TYPES: LazyLock> = + LazyLock::new(|| Mutex::new(CustomEventTypeMaps::new())); impl crate::EventSubsystem { /// Removes all events in the event queue that match the specified event type. diff --git a/src/sdl2/lib.rs b/src/sdl2/lib.rs index ee827cff31..8fffa0ce9d 100644 --- a/src/sdl2/lib.rs +++ b/src/sdl2/lib.rs @@ -50,9 +50,6 @@ pub extern crate libc; -#[macro_use] -extern crate lazy_static; - #[macro_use] extern crate bitflags; pub extern crate sdl2_sys as sys; diff --git a/tests/events.rs b/tests/events.rs index ca96e1f4f5..4a22eda5fd 100644 --- a/tests/events.rs +++ b/tests/events.rs @@ -1,6 +1,5 @@ extern crate sdl2; -#[macro_use] -extern crate lazy_static; +use std::sync::LazyLock; use sdl2::event; use std::sync::Mutex; @@ -8,9 +7,7 @@ use std::sync::Mutex; // Since only one `Sdl` context instance can be created at a time, running tests in parallel causes // 'Cannot initialize `Sdl` more than once at a time' error. To avoid it, run tests in serial by // locking this mutex. -lazy_static! { - static ref CONTEXT_MUTEX: Mutex<()> = Mutex::new(()); -} +static CONTEXT_MUTEX: LazyLock> = LazyLock::new(|| Mutex::new(())); #[test] fn test_events() {