diff --git a/src/platform_impl/web/async.rs b/src/platform_impl/web/async.rs index 8aa70e3411..801c4f4e6a 100644 --- a/src/platform_impl/web/async.rs +++ b/src/platform_impl/web/async.rs @@ -1,5 +1,4 @@ use atomic_waker::AtomicWaker; -use once_cell::unsync::Lazy; use std::future; use std::marker::PhantomData; use std::ops::Deref; @@ -25,7 +24,7 @@ pub struct MainThreadSafe { impl MainThreadSafe { thread_local! { - static MAIN_THREAD: Lazy = Lazy::new(|| { + static MAIN_THREAD: bool = { #[wasm_bindgen] extern "C" { #[derive(Clone)] @@ -37,13 +36,13 @@ impl MainThreadSafe { let global: Global = js_sys::global().unchecked_into(); !global.window().is_undefined() - }); + }; } #[track_caller] fn new(value: T, handler: fn(&RwLock>, E)) -> Option { Self::MAIN_THREAD.with(|safe| { - if !*safe.deref() { + if !safe { panic!("only callable from inside the `Window`") } }); @@ -75,7 +74,7 @@ impl MainThreadSafe { pub fn send(&self, event: E) { Self::MAIN_THREAD.with(|is_main_thread| { - if *is_main_thread.deref() { + if *is_main_thread { (self.handler)(&self.value, event) } else { self.sender.send(event).unwrap() @@ -84,12 +83,12 @@ impl MainThreadSafe { } fn is_main_thread(&self) -> bool { - Self::MAIN_THREAD.with(|is_main_thread| *is_main_thread.deref()) + Self::MAIN_THREAD.with(|is_main_thread| *is_main_thread) } pub fn with(&self, f: impl FnOnce(&T) -> R) -> Option { Self::MAIN_THREAD.with(|is_main_thread| { - if *is_main_thread.deref() { + if *is_main_thread { Some(f(self.value.read().unwrap().as_ref().unwrap())) } else { None diff --git a/src/platform_impl/web/web_sys/fullscreen.rs b/src/platform_impl/web/web_sys/fullscreen.rs index 7a5b4f5aad..6ad1ae3e5b 100644 --- a/src/platform_impl/web/web_sys/fullscreen.rs +++ b/src/platform_impl/web/web_sys/fullscreen.rs @@ -2,7 +2,7 @@ use std::cell::Cell; use std::rc::Rc; use js_sys::Promise; -use once_cell::unsync::{Lazy, OnceCell}; +use once_cell::unsync::OnceCell; use wasm_bindgen::closure::Closure; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsCast, JsValue}; @@ -65,7 +65,7 @@ impl FullscreenHandler { if has_fullscreen_api_support(&self.canvas) { thread_local! { - static REJECT_HANDLER: Lazy> = Lazy::new(|| Closure::new(|_| ())); + static REJECT_HANDLER: Closure = Closure::new(|_| ()); } REJECT_HANDLER.with(|handler| { let _ = canvas.request_fullscreen().catch(handler); diff --git a/src/platform_impl/web/web_sys/resize_scaling.rs b/src/platform_impl/web/web_sys/resize_scaling.rs index 8ecd1bd564..75776d210f 100644 --- a/src/platform_impl/web/web_sys/resize_scaling.rs +++ b/src/platform_impl/web/web_sys/resize_scaling.rs @@ -1,5 +1,4 @@ use js_sys::{Array, Object}; -use once_cell::unsync::Lazy; use wasm_bindgen::prelude::{wasm_bindgen, Closure}; use wasm_bindgen::{JsCast, JsValue}; use web_sys::{ @@ -292,7 +291,7 @@ impl Drop for ResizeScaleInternal { // See . pub fn has_device_pixel_support() -> bool { thread_local! { - static DEVICE_PIXEL_SUPPORT: Lazy = Lazy::new(|| { + static DEVICE_PIXEL_SUPPORT: bool = { #[wasm_bindgen] extern "C" { type ResizeObserverEntryExt; @@ -307,8 +306,8 @@ pub fn has_device_pixel_support() -> bool { &JsValue::from_str("devicePixelContentBoxSize"), ); !descriptor.is_undefined() - }); + }; } - DEVICE_PIXEL_SUPPORT.with(|support| **support) + DEVICE_PIXEL_SUPPORT.with(|support| *support) } diff --git a/src/platform_impl/web/web_sys/schedule.rs b/src/platform_impl/web/web_sys/schedule.rs index 7810b3fcd5..b229fd3a2b 100644 --- a/src/platform_impl/web/web_sys/schedule.rs +++ b/src/platform_impl/web/web_sys/schedule.rs @@ -1,5 +1,5 @@ use js_sys::{Function, Object, Promise, Reflect}; -use once_cell::unsync::{Lazy, OnceCell}; +use once_cell::unsync::OnceCell; use std::time::Duration; use wasm_bindgen::closure::Closure; use wasm_bindgen::prelude::wasm_bindgen; @@ -73,7 +73,7 @@ impl Schedule { } thread_local! { - static REJECT_HANDLER: Lazy> = Lazy::new(|| Closure::new(|_| ())); + static REJECT_HANDLER: Closure = Closure::new(|_| ()); } REJECT_HANDLER.with(|handler| { let _ = scheduler