diff --git a/Cargo.toml b/Cargo.toml index d99fc37..857f9ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,6 @@ plotters = { version = "0.3", default-features = false } plotters-backend = "0.3" iced_widget = { version = "0.14", features = ["canvas"] } iced_graphics = "0.14" -once_cell = "1" [dev-dependencies] plotters = { version = "0.3", default-features = false, features = [ diff --git a/src/backend/mod.rs b/src/backend/mod.rs index cc5ad2a..5ee57a2 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -14,7 +14,6 @@ use iced_widget::{ text::Alignment, text::Shaping, }; -use once_cell::unsync::Lazy; use plotters_backend::{ //FontTransform, BackendColor, @@ -28,6 +27,7 @@ use plotters_backend::{ text_anchor, }; use std::collections::HashSet; +use std::sync::{LazyLock, Mutex}; /// The Iced drawing backend pub(crate) struct IcedChartBackend<'a, B> { @@ -302,25 +302,26 @@ where } } -#[allow(static_mut_refs)] fn style_to_font(style: &S) -> Font { // iced font family requires static str - static mut FONTS: Lazy> = Lazy::new(HashSet::new); + static FONTS: LazyLock>> = + LazyLock::new(|| Mutex::new(HashSet::new())); Font { family: match style.family() { FontFamily::Serif => font::Family::Serif, FontFamily::SansSerif => font::Family::SansSerif, FontFamily::Monospace => font::Family::Monospace, - FontFamily::Name(s) => { - let s = unsafe { - if !FONTS.contains(s) { - FONTS.insert(String::from(s)); + FontFamily::Name(s) => FONTS.lock().map_or_else( + |_| font::Family::default(), + |mut vec_guard| { + if !vec_guard.contains(s) { + vec_guard.insert(String::from(s).leak()); } - FONTS.get(s).unwrap().as_str() - }; - font::Family::Name(s) - } + + font::Family::Name(*vec_guard.get(s).unwrap()) + }, + ), }, weight: match style.style() { FontStyle::Bold => font::Weight::Bold,