Skip to content

Commit 7aed3d8

Browse files
authored
refactor: lazy_static -> LazyLock (#1524)
1 parent de686d0 commit 7aed3d8

4 files changed

Lines changed: 5 additions & 14 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ path = "src/sdl2/lib.rs"
1919
[dependencies]
2020
bitflags = "2.10.0"
2121
libc = "0.2.92"
22-
lazy_static = "1.5.0"
2322

2423
[dependencies.sdl2-sys]
2524
path = "sdl2-sys"

src/sdl2/event.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::marker::PhantomData;
99
use std::mem;
1010
use std::mem::transmute;
1111
use std::ptr;
12-
use std::sync::Mutex;
12+
use std::sync::{LazyLock, Mutex};
1313

1414
use libc::c_int;
1515
use libc::c_void;
@@ -44,10 +44,8 @@ impl CustomEventTypeMaps {
4444
}
4545
}
4646

47-
lazy_static! {
48-
static ref CUSTOM_EVENT_TYPES: Mutex<CustomEventTypeMaps> =
49-
Mutex::new(CustomEventTypeMaps::new());
50-
}
47+
static CUSTOM_EVENT_TYPES: LazyLock<Mutex<CustomEventTypeMaps>> =
48+
LazyLock::new(|| Mutex::new(CustomEventTypeMaps::new()));
5149

5250
impl crate::EventSubsystem {
5351
/// Removes all events in the event queue that match the specified event type.

src/sdl2/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@
5050

5151
pub extern crate libc;
5252

53-
#[macro_use]
54-
extern crate lazy_static;
55-
5653
#[macro_use]
5754
extern crate bitflags;
5855
pub extern crate sdl2_sys as sys;

tests/events.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
extern crate sdl2;
2-
#[macro_use]
3-
extern crate lazy_static;
2+
use std::sync::LazyLock;
43

54
use sdl2::event;
65
use std::sync::Mutex;
76

87
// Since only one `Sdl` context instance can be created at a time, running tests in parallel causes
98
// 'Cannot initialize `Sdl` more than once at a time' error. To avoid it, run tests in serial by
109
// locking this mutex.
11-
lazy_static! {
12-
static ref CONTEXT_MUTEX: Mutex<()> = Mutex::new(());
13-
}
10+
static CONTEXT_MUTEX: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
1411

1512
#[test]
1613
fn test_events() {

0 commit comments

Comments
 (0)