Skip to content

Commit b55f576

Browse files
authored
Remove lazy static dependency (#1174)
* deps: remove lazy_static from dependencies * fix: clippy
1 parent e196538 commit b55f576

File tree

24 files changed

+490
-554
lines changed

24 files changed

+490
-554
lines changed

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ x11 = [ "dep:gdkx11-sys", "dep:x11-dl" ]
3939
members = [ "tao-macros" ]
4040

4141
[dependencies]
42-
lazy_static = "1"
4342
libc = "0.2"
4443
log = "0.4"
44+
once_cell = "1"
4545
serde = { version = "1", optional = true, features = [ "serde_derive" ] }
4646
rwh_04 = { package = "raw-window-handle", version = "0.4", optional = true }
4747
rwh_05 = { package = "raw-window-handle", version = "0.5", features = [ "std" ], optional = true }
@@ -96,9 +96,6 @@ windows-core = "0.61"
9696
"Win32_UI_WindowsAndMessaging"
9797
]
9898

99-
[target."cfg(any(target_os = \"android\", target_os = \"windows\"))".dependencies]
100-
once_cell = "1"
101-
10299
[target."cfg(target_os = \"android\")".dependencies]
103100
jni = "0.21"
104101
ndk = "0.9"

examples/window_run_return.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn main() {
3030

3131
if let Event::WindowEvent { event, .. } = &event {
3232
// Print only Window events to reduce noise
33-
println!("{:?}", event);
33+
println!("{event:?}");
3434
}
3535

3636
match event {

src/event_loop.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ impl<T> EventLoopBuilder<T> {
112112
#[inline]
113113
pub fn build(&mut self) -> EventLoop<T> {
114114
EventLoop {
115+
#[cfg_attr(
116+
any(
117+
target_os = "linux",
118+
target_os = "dragonfly",
119+
target_os = "freebsd",
120+
target_os = "netbsd",
121+
target_os = "openbsd"
122+
),
123+
allow(clippy::unnecessary_mut_passed)
124+
)]
115125
event_loop: platform_impl::EventLoop::new(&mut self.platform_specific),
116126
_marker: PhantomData,
117127
}

src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ pub use rwh_05;
155155
#[cfg(feature = "rwh_06")]
156156
pub use rwh_06;
157157

158-
#[allow(unused_imports)]
159-
#[macro_use]
160-
extern crate lazy_static;
161158
#[allow(unused_imports)]
162159
#[macro_use]
163160
extern crate log;

src/platform/unix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl WindowExtUnix for Window {
106106
window: gtk::ApplicationWindow,
107107
) -> Result<Window, OsError> {
108108
let window = UnixWindow::new_from_gtk_window(&event_loop_window_target.p, window)?;
109-
Ok(Window { window: window })
109+
Ok(Window { window })
110110
}
111111

112112
fn set_badge_count(&self, count: Option<i64>, desktop_filename: Option<String>) {

src/platform_impl/android/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use ndk::{
1717
event::{InputEvent, KeyAction, MotionAction},
1818
looper::{ForeignLooper, Poll, ThreadLooper},
1919
};
20+
use once_cell::sync::Lazy;
2021
use std::{
2122
collections::VecDeque,
2223
sync::RwLock,
@@ -26,9 +27,7 @@ use std::{
2627
pub mod ndk_glue;
2728
use ndk_glue::{Event, Rect};
2829

29-
lazy_static! {
30-
static ref CONFIG: RwLock<Configuration> = RwLock::new(Configuration::new());
31-
}
30+
static CONFIG: Lazy<RwLock<Configuration>> = Lazy::new(|| RwLock::new(Configuration::new()));
3231

3332
enum EventSource {
3433
Callback,

src/platform_impl/ios/app_state.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::{
1414
};
1515

1616
use objc2::runtime::AnyObject;
17+
use once_cell::sync::Lazy;
1718

1819
use crate::{
1920
dpi::LogicalSize,
@@ -1005,29 +1006,24 @@ impl NSOperatingSystemVersion {
10051006
}
10061007

10071008
pub fn os_capabilities() -> OSCapabilities {
1008-
lazy_static! {
1009-
static ref OS_CAPABILITIES: OSCapabilities = {
1010-
let version: NSOperatingSystemVersion = unsafe {
1011-
let process_info: id = msg_send![class!(NSProcessInfo), processInfo];
1012-
let atleast_ios_8: bool = msg_send![
1013-
process_info,
1014-
respondsToSelector: sel!(operatingSystemVersion)
1015-
];
1016-
// tao requires atleast iOS 8 because no one has put the time into supporting earlier os versions.
1017-
// Older iOS versions are increasingly difficult to test. For example, Xcode 11 does not support
1018-
// debugging on devices with an iOS version of less than 8. Another example, in order to use an iOS
1019-
// simulator older than iOS 8, you must download an older version of Xcode (<9), and at least Xcode 7
1020-
// has been tested to not even run on macOS 10.15 - Xcode 8 might?
1021-
//
1022-
// The minimum required iOS version is likely to grow in the future.
1023-
assert!(
1024-
atleast_ios_8,
1025-
"`tao` requires iOS version 8 or greater"
1026-
);
1027-
msg_send![process_info, operatingSystemVersion]
1028-
};
1029-
version.into()
1030-
};
1031-
}
1009+
static OS_CAPABILITIES: Lazy<OSCapabilities> = Lazy::new(|| {
1010+
let version: NSOperatingSystemVersion = unsafe {
1011+
let process_info: id = msg_send![class!(NSProcessInfo), processInfo];
1012+
let atleast_ios_8: bool = msg_send![
1013+
process_info,
1014+
respondsToSelector: sel!(operatingSystemVersion)
1015+
];
1016+
// tao requires atleast iOS 8 because no one has put the time into supporting earlier os versions.
1017+
// Older iOS versions are increasingly difficult to test. For example, Xcode 11 does not support
1018+
// debugging on devices with an iOS version of less than 8. Another example, in order to use an iOS
1019+
// simulator older than iOS 8, you must download an older version of Xcode (<9), and at least Xcode 7
1020+
// has been tested to not even run on macOS 10.15 - Xcode 8 might?
1021+
//
1022+
// The minimum required iOS version is likely to grow in the future.
1023+
assert!(atleast_ios_8, "`tao` requires iOS version 8 or greater");
1024+
msg_send![process_info, operatingSystemVersion]
1025+
};
1026+
version.into()
1027+
});
10321028
OS_CAPABILITIES.clone()
10331029
}

src/platform_impl/linux/device.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,32 @@ pub fn spawn(device_tx: glib::Sender<DeviceEvent>) {
4545
}
4646

4747
let event_type = event.get_type();
48-
match event_type {
49-
xlib::GenericEvent => {
50-
let mut xev = event.generic_event_cookie;
51-
if (xlib.XGetEventData)(display, &mut xev) == xlib::True {
52-
match xev.evtype {
53-
xinput2::XI_RawKeyPress | xinput2::XI_RawKeyRelease => {
54-
let xev: &xinput2::XIRawEvent = &*(xev.data as *const _);
55-
let physical_key = keycode_from_scancode(xev.detail as u32);
56-
let state = match xev.evtype {
57-
xinput2::XI_RawKeyPress => ElementState::Pressed,
58-
xinput2::XI_RawKeyRelease => ElementState::Released,
59-
_ => unreachable!(),
60-
};
48+
if event_type == xlib::GenericEvent {
49+
let mut xev = event.generic_event_cookie;
50+
if (xlib.XGetEventData)(display, &mut xev) == xlib::True {
51+
match xev.evtype {
52+
xinput2::XI_RawKeyPress | xinput2::XI_RawKeyRelease => {
53+
let xev: &xinput2::XIRawEvent = &*(xev.data as *const _);
54+
let physical_key = keycode_from_scancode(xev.detail as u32);
55+
let state = match xev.evtype {
56+
xinput2::XI_RawKeyPress => ElementState::Pressed,
57+
xinput2::XI_RawKeyRelease => ElementState::Released,
58+
_ => unreachable!(),
59+
};
6160

62-
let event = RawKeyEvent {
63-
physical_key,
64-
state,
65-
};
61+
let event = RawKeyEvent {
62+
physical_key,
63+
state,
64+
};
6665

67-
if let Err(e) = device_tx.send(DeviceEvent::Key(event)) {
68-
log::info!("Failed to send device event {} since receiver is closed. Closing x11 thread along with it", e);
69-
break;
70-
}
66+
if let Err(e) = device_tx.send(DeviceEvent::Key(event)) {
67+
log::info!("Failed to send device event {} since receiver is closed. Closing x11 thread along with it", e);
68+
break;
7169
}
72-
_ => {}
7370
}
71+
_ => {}
7472
}
7573
}
76-
_ => {}
7774
}
7875
}
7976
});

src/platform_impl/linux/event_loop.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ impl<T> EventLoopWindowTarget<T> {
8787
#[inline]
8888
pub fn primary_monitor(&self) -> Option<RootMonitorHandle> {
8989
let monitor = self.display.primary_monitor();
90-
monitor.and_then(|monitor| {
91-
let handle = MonitorHandle { monitor };
92-
Some(RootMonitorHandle { inner: handle })
90+
monitor.map(|monitor| RootMonitorHandle {
91+
inner: MonitorHandle { monitor },
9392
})
9493
}
9594

@@ -910,7 +909,7 @@ impl<T: 'static> EventLoop<T> {
910909
let background_color = unsafe {
911910
window
912911
.data::<Option<crate::window::RGBA>>("background_color")
913-
.and_then(|c| c.as_ref().clone())
912+
.and_then(|c| *c.as_ref())
914913
};
915914

916915
let rgba = background_color
@@ -1010,7 +1009,7 @@ impl<T: 'static> EventLoop<T> {
10101009
/// There are a dew notibale event will sent to callback when state is transisted:
10111010
/// - On any state moves to `LoopDestroyed`, a `LoopDestroyed` event is sent.
10121011
/// - On `NewStart` to `EventQueue`, a `NewEvents` with corresponding `StartCause` depends on
1013-
/// current control flow is sent.
1012+
/// current control flow is sent.
10141013
/// - On `EventQueue` to `DrawQueue`, a `MainEventsCleared` event is sent.
10151014
/// - On `DrawQueue` back to `NewStart`, a `RedrawEventsCleared` event is sent.
10161015
pub(crate) fn run_return<F>(&mut self, mut callback: F) -> i32
@@ -1097,7 +1096,7 @@ impl<T: 'static> EventLoop<T> {
10971096
EventState::EventQueue => match control_flow {
10981097
ControlFlow::ExitWithCode(code) => {
10991098
callback(Event::LoopDestroyed, window_target, &mut control_flow);
1100-
break (code);
1099+
break code;
11011100
}
11021101
_ => match events.try_recv() {
11031102
Ok(event) => match event {

0 commit comments

Comments
 (0)