From b71f69ade986375682a25214cf3fb097419ff479 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Tue, 7 Feb 2023 08:05:16 +0100 Subject: [PATCH] Use Cell instead of RefCell (#166) --- src/lib.rs | 3 ++- yewprint-css/src/lib.rs | 2 +- yewprint-doc/src/app.rs | 4 ++-- yewprint-doc/src/lib.rs | 9 +++++---- yewprint-doc/src/overlay/example.rs | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 63528cd..9541535 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,8 @@ clippy::needless_update, clippy::inconsistent_struct_constructor, clippy::type_complexity, - clippy::derive_partial_eq_without_eq + clippy::derive_partial_eq_without_eq, + clippy::uninlined_format_args )] mod button_group; diff --git a/yewprint-css/src/lib.rs b/yewprint-css/src/lib.rs index 1152a4d..8391315 100644 --- a/yewprint-css/src/lib.rs +++ b/yewprint-css/src/lib.rs @@ -31,7 +31,7 @@ pub fn download_from_npm_package( let version = if version.is_empty() || version == "latest" { let info: PackageInfo = - ureq::get(format!("https://registry.npmjs.org/{}", package_name).as_str()) + ureq::get(format!("https://registry.npmjs.org/{package_name}").as_str()) .call()? .into_json()?; diff --git a/yewprint-doc/src/app.rs b/yewprint-doc/src/app.rs index 4aa3852..05b8846 100644 --- a/yewprint-doc/src/app.rs +++ b/yewprint-doc/src/app.rs @@ -55,7 +55,7 @@ impl Component for App { fn update(&mut self, ctx: &Context, msg: Self::Message) -> bool { match msg { Msg::ToggleLight => { - DARK.with(|x| x.replace_with(|&mut x| !x)); + DARK.with(|x| x.replace(!x.get())); } Msg::GoToMenu(event, doc_menu) => { event.prevent_default(); @@ -70,7 +70,7 @@ impl Component for App { } fn view(&self, ctx: &Context) -> Html { - let dark = DARK.with(|x| *x.borrow()); + let dark = DARK.with(|x| x.get()); let netlify_badge = if dark { "https://www.netlify.com/img/global/badges/netlify-color-accent.svg" diff --git a/yewprint-doc/src/lib.rs b/yewprint-doc/src/lib.rs index a941922..efe82f6 100644 --- a/yewprint-doc/src/lib.rs +++ b/yewprint-doc/src/lib.rs @@ -4,7 +4,8 @@ dead_code, clippy::derive_partial_eq_without_eq, // Shadows lints linked to this issue: https://github.com/yewstack/yew/issues/2931 - clippy::let_unit_value + clippy::let_unit_value, + clippy::uninlined_format_args )] mod app; @@ -39,11 +40,11 @@ mod tree; pub use app::*; pub use example::*; pub use logo::*; -use std::cell::RefCell; +use std::cell::Cell; thread_local! { - pub static DARK: RefCell = { - RefCell::new(web_sys::window() + pub static DARK: Cell = { + Cell::new(web_sys::window() .and_then(|x| x.match_media("(prefers-color-scheme: dark)").ok().flatten()) .map(|x| x.matches()) .unwrap_or(true)) diff --git a/yewprint-doc/src/overlay/example.rs b/yewprint-doc/src/overlay/example.rs index 2011e22..437c323 100644 --- a/yewprint-doc/src/overlay/example.rs +++ b/yewprint-doc/src/overlay/example.rs @@ -63,7 +63,7 @@ impl Component for Example { onclose={ctx.link().callback(|_| Msg::Close)} {backdrop} class={classes!( - DARK.with(|x| x.borrow().then_some("bp3-dark")), + DARK.with(|x| x.get().then_some("bp3-dark")), self.tall.then_some("docs-overlay-example-tall"), )} style="left: calc(50vw - 200px); margin: 10vh 0; top: 0; width: 400px;"