From 4b7455748d9273aae8a129d07fc0352f650ffb0b Mon Sep 17 00:00:00 2001 From: Pauan Date: Fri, 28 May 2021 15:18:14 +0200 Subject: [PATCH] Replacing lazy_static with once_cell --- Cargo.toml | 2 +- src/dom.rs | 16 ++++++---------- src/routing.rs | 6 ++---- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 995de10..de7ea33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ default = ["wasm-bindgen/enable-interning"] nightly = [] [dependencies] -lazy_static = "1.3.0" +once_cell = "1.7.2" discard = "1.0.3" pin-project = "1.0.1" futures-channel = "0.3.0" diff --git a/src/dom.rs b/src/dom.rs index 044d268..24eabee 100644 --- a/src/dom.rs +++ b/src/dom.rs @@ -4,7 +4,7 @@ use std::convert::AsRef; use std::future::Future; use std::task::{Context, Poll}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use futures_signals::signal::{Signal, not}; use futures_signals::signal_vec::SignalVec; use futures_util::FutureExt; @@ -77,11 +77,9 @@ const SVG_NAMESPACE: &str = "http://www.w3.org/2000/svg"; pub const HIGHEST_ZINDEX: &str = "2147483647"; -lazy_static! { - static ref HIDDEN_CLASS: String = class! { - .style_important("display", "none") - }; -} +static HIDDEN_CLASS: Lazy = Lazy::new(|| class! { + .style_important("display", "none") +}); // TODO should return HtmlBodyElement ? @@ -1211,7 +1209,7 @@ mod tests { use super::{DomBuilder, text_signal, RefFn}; use crate::{html, shadow_root, ShadowRootMode, with_cfg}; use futures_signals::signal::{always, SignalExt}; - use lazy_static::lazy_static; + use once_cell::sync::Lazy; use web_sys::HtmlElement; #[test] @@ -1304,9 +1302,7 @@ mod tests { #[test] fn style_signal_types() { - lazy_static! { - static ref FOO: String = "foo".to_owned(); - } + static FOO: Lazy = Lazy::new(|| "foo".to_owned()); let _a: DomBuilder = DomBuilder::new_html("div") .style_signal("foo", always("bar")) diff --git a/src/routing.rs b/src/routing.rs index 8d1d44d..a72b4fe 100644 --- a/src/routing.rs +++ b/src/routing.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use web_sys::{EventTarget, HtmlElement}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use futures_signals::signal::{Mutable, ReadOnlyMutable}; use crate::bindings; @@ -48,9 +48,7 @@ impl CurrentUrl { } -lazy_static! { - static ref URL: CurrentUrl = CurrentUrl::new(); -} +static URL: Lazy = Lazy::new(|| CurrentUrl::new()); #[inline]