From ea349aca82eecd1edabee376203608f94851d8dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vuka=C5=A1in=20Vojinovi=C4=87?= <150025636+git-f0x@users.noreply.github.com> Date: Wed, 3 Sep 2025 20:22:06 +0200 Subject: [PATCH] chore: use `std::syncLazyLock` Also migrates workspace members to Rust 2024. --- Cargo.toml | 1 - cosmic-config/Cargo.toml | 3 +- cosmic-config/src/dbus.rs | 5 +-- cosmic-config/src/lib.rs | 4 +-- cosmic-config/src/subscription.rs | 2 +- cosmic-theme/Cargo.toml | 3 +- cosmic-theme/src/model/cosmic_palette.rs | 17 +++++---- cosmic-theme/src/model/theme.rs | 6 ++-- cosmic-theme/src/output/gtk4_output.rs | 6 ++-- cosmic-theme/src/output/mod.rs | 2 +- cosmic-theme/src/output/vs_code.rs | 2 +- cosmic-theme/src/steps.rs | 2 +- src/theme/mod.rs | 46 +++++++++++++----------- src/widget/calendar.rs | 18 +++------- src/widget/color_picker/mod.rs | 18 +++++----- 15 files changed, 64 insertions(+), 71 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a8fcdae..33bf7c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -114,7 +114,6 @@ image = { version = "0.25.8", default-features = false, features = [ "jpeg", "png", ] } -lazy_static = "1.5.0" libc = { version = "0.2.175", optional = true } license = { version = "3.7.0", optional = true } mime = { version = "0.3.17", optional = true } diff --git a/cosmic-config/Cargo.toml b/cosmic-config/Cargo.toml index 4d7b99e..e838f9b 100644 --- a/cosmic-config/Cargo.toml +++ b/cosmic-config/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cosmic-config" version = "0.1.0" -edition = "2021" +edition = "2024" [features] default = ["macro", "subscription"] @@ -20,7 +20,6 @@ serde = "1.0.219" cosmic-config-derive = { path = "../cosmic-config-derive/", optional = true } iced = { path = "../iced/", default-features = false, optional = true } iced_futures = { path = "../iced/futures/", default-features = false, optional = true } -once_cell = "1.21.3" futures-util = { version = "0.3", optional = true } dirs.workspace = true tokio = { version = "1.47", optional = true, features = ["time"] } diff --git a/cosmic-config/src/dbus.rs b/cosmic-config/src/dbus.rs index f8256bc..e9e3395 100644 --- a/cosmic-config/src/dbus.rs +++ b/cosmic-config/src/dbus.rs @@ -4,8 +4,9 @@ use crate::{CosmicConfigEntry, Update}; use cosmic_settings_daemon::{Changed, ConfigProxy, CosmicSettingsDaemonProxy}; use futures_util::SinkExt; use iced_futures::{ - futures::{self, future::pending, Stream, StreamExt}, - stream, Subscription, + Subscription, + futures::{self, Stream, StreamExt, future::pending}, + stream, }; pub async fn settings_daemon_proxy() -> zbus::Result> { diff --git a/cosmic-config/src/lib.rs b/cosmic-config/src/lib.rs index 8759a52..72b0237 100644 --- a/cosmic-config/src/lib.rs +++ b/cosmic-config/src/lib.rs @@ -1,10 +1,10 @@ //! Integrations for cosmic-config — the cosmic configuration system. use notify::{ - event::{EventKind, ModifyKind, RenameMode}, RecommendedWatcher, Watcher, + event::{EventKind, ModifyKind, RenameMode}, }; -use serde::{de::DeserializeOwned, Serialize}; +use serde::{Serialize, de::DeserializeOwned}; use std::{ fmt, fs, io::Write, diff --git a/cosmic-config/src/subscription.rs b/cosmic-config/src/subscription.rs index 6425595..88f8bfa 100644 --- a/cosmic-config/src/subscription.rs +++ b/cosmic-config/src/subscription.rs @@ -62,7 +62,7 @@ async fn start_listening, output: &mut mpsc::Sender>, ) -> ConfigState { - use iced_futures::futures::{future::pending, StreamExt}; + use iced_futures::futures::{StreamExt, future::pending}; match state { ConfigState::Init(config_id, version, is_state) => { diff --git a/cosmic-theme/Cargo.toml b/cosmic-theme/Cargo.toml index bb73534..44b0df5 100644 --- a/cosmic-theme/Cargo.toml +++ b/cosmic-theme/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cosmic-theme" version = "0.1.0" -edition = "2021" +edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -22,7 +22,6 @@ serde_json = { version = "1.0.143", optional = true, features = [ "preserve_order", ] } ron = "0.11.0" -lazy_static = "1.5.0" csscolorparser = { version = "0.7.2", features = ["serde"] } cosmic-config = { path = "../cosmic-config/", default-features = false, features = [ "subscription", diff --git a/cosmic-theme/src/model/cosmic_palette.rs b/cosmic-theme/src/model/cosmic_palette.rs index 6a18908..3852742 100644 --- a/cosmic-theme/src/model/cosmic_palette.rs +++ b/cosmic-theme/src/model/cosmic_palette.rs @@ -1,15 +1,14 @@ -use lazy_static::lazy_static; use palette::Srgba; use serde::{Deserialize, Serialize}; +use std::sync::LazyLock; -lazy_static! { - /// built in light palette - pub static ref LIGHT_PALETTE: CosmicPalette = - ron::from_str(include_str!("light.ron")).unwrap(); - /// built in dark palette - pub static ref DARK_PALETTE: CosmicPalette = - ron::from_str(include_str!("dark.ron")).unwrap(); -} +/// built-in light palette +pub static LIGHT_PALETTE: LazyLock = + LazyLock::new(|| ron::from_str(include_str!("light.ron")).unwrap()); + +/// built-in dark palette +pub static DARK_PALETTE: LazyLock = + LazyLock::new(|| ron::from_str(include_str!("dark.ron")).unwrap()); /// Palette type #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] diff --git a/cosmic-theme/src/model/theme.rs b/cosmic-theme/src/model/theme.rs index 7bfd41c..d1d3ae0 100644 --- a/cosmic-theme/src/model/theme.rs +++ b/cosmic-theme/src/model/theme.rs @@ -1,12 +1,12 @@ use crate::{ + Component, Container, CornerRadii, CosmicPalette, CosmicPaletteInner, DARK_PALETTE, + LIGHT_PALETTE, NAME, Spacing, ThemeMode, composite::over, steps::{color_index, get_small_widget_color, get_surface_color, get_text, steps}, - Component, Container, CornerRadii, CosmicPalette, CosmicPaletteInner, Spacing, ThemeMode, - DARK_PALETTE, LIGHT_PALETTE, NAME, }; use cosmic_config::{Config, CosmicConfigEntry}; use palette::{ - color_difference::Wcag21RelativeContrast, rgb::Rgb, IntoColor, Oklcha, Srgb, Srgba, WithAlpha, + IntoColor, Oklcha, Srgb, Srgba, WithAlpha, color_difference::Wcag21RelativeContrast, rgb::Rgb, }; use serde::{Deserialize, Serialize}; use std::num::NonZeroUsize; diff --git a/cosmic-theme/src/output/gtk4_output.rs b/cosmic-theme/src/output/gtk4_output.rs index 9d7210f..df6aca6 100644 --- a/cosmic-theme/src/output/gtk4_output.rs +++ b/cosmic-theme/src/output/gtk4_output.rs @@ -1,5 +1,5 @@ -use crate::{composite::over, steps::steps, Component, Theme}; -use palette::{rgb::Rgba, Darken, IntoColor, Lighten, Srgba, WithAlpha}; +use crate::{Component, Theme, composite::over, steps::steps}; +use palette::{Darken, IntoColor, Lighten, Srgba, WithAlpha, rgb::Rgba}; use std::{ fs::{self, File}, io::{self, Write}, @@ -7,7 +7,7 @@ use std::{ path::Path, }; -use super::{to_rgba, OutputError}; +use super::{OutputError, to_rgba}; impl Theme { #[must_use] diff --git a/cosmic-theme/src/output/mod.rs b/cosmic-theme/src/output/mod.rs index f2eb6b4..832771d 100644 --- a/cosmic-theme/src/output/mod.rs +++ b/cosmic-theme/src/output/mod.rs @@ -1,4 +1,4 @@ -use palette::{rgb::Rgba, Srgba}; +use palette::{Srgba, rgb::Rgba}; use thiserror::Error; use crate::Theme; diff --git a/cosmic-theme/src/output/vs_code.rs b/cosmic-theme/src/output/vs_code.rs index 5c770cd..b07c82e 100644 --- a/cosmic-theme/src/output/vs_code.rs +++ b/cosmic-theme/src/output/vs_code.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::Theme; -use super::{to_hex, OutputError}; +use super::{OutputError, to_hex}; /// Represents the workbench.colorCustomizations section of a VS Code settings.json file #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cosmic-theme/src/steps.rs b/cosmic-theme/src/steps.rs index 506b6fa..6c0779c 100644 --- a/cosmic-theme/src/steps.rs +++ b/cosmic-theme/src/steps.rs @@ -1,7 +1,7 @@ use std::num::NonZeroUsize; use almost::equal; -use palette::{convert::FromColorUnclamped, ClampAssign, FromColor, Lch, Oklcha, Srgb, Srgba}; +use palette::{ClampAssign, FromColor, Lch, Oklcha, Srgb, Srgba, convert::FromColorUnclamped}; /// Get an array of 100 colors with a specific hue and chroma /// over the full range of lightness. diff --git a/src/theme/mod.rs b/src/theme/mod.rs index 9c4e7d5..f01180c 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -15,33 +15,37 @@ use cosmic_theme::Spacing; use cosmic_theme::ThemeMode; use iced_futures::Subscription; use iced_runtime::{Appearance, DefaultStyle}; -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, LazyLock, Mutex}; pub use style::*; pub type CosmicColor = ::palette::rgb::Srgba; pub type CosmicComponent = cosmic_theme::Component; pub type CosmicTheme = cosmic_theme::Theme; -lazy_static::lazy_static! { - pub static ref COSMIC_DARK: CosmicTheme = CosmicTheme::dark_default(); - pub static ref COSMIC_HC_DARK: CosmicTheme = CosmicTheme::high_contrast_dark_default(); - pub static ref COSMIC_LIGHT: CosmicTheme = CosmicTheme::light_default(); - pub static ref COSMIC_HC_LIGHT: CosmicTheme = CosmicTheme::high_contrast_light_default(); - pub static ref TRANSPARENT_COMPONENT: Component = Component { - base: CosmicColor::new(0.0, 0.0, 0.0, 0.0), - hover: CosmicColor::new(0.0, 0.0, 0.0, 0.0), - pressed: CosmicColor::new(0.0, 0.0, 0.0, 0.0), - selected: CosmicColor::new(0.0, 0.0, 0.0, 0.0), - selected_text: CosmicColor::new(0.0, 0.0, 0.0, 0.0), - focus: CosmicColor::new(0.0, 0.0, 0.0, 0.0), - disabled: CosmicColor::new(0.0, 0.0, 0.0, 0.0), - on: CosmicColor::new(0.0, 0.0, 0.0, 0.0), - on_disabled: CosmicColor::new(0.0, 0.0, 0.0, 0.0), - divider: CosmicColor::new(0.0, 0.0, 0.0, 0.0), - border: CosmicColor::new(0.0, 0.0, 0.0, 0.0), - disabled_border: CosmicColor::new(0.0, 0.0, 0.0, 0.0), - }; -} +pub static COSMIC_DARK: LazyLock = LazyLock::new(|| CosmicTheme::dark_default()); + +pub static COSMIC_HC_DARK: LazyLock = + LazyLock::new(|| CosmicTheme::high_contrast_dark_default()); + +pub static COSMIC_LIGHT: LazyLock = LazyLock::new(|| CosmicTheme::light_default()); + +pub static COSMIC_HC_LIGHT: LazyLock = + LazyLock::new(|| CosmicTheme::high_contrast_light_default()); + +pub static TRANSPARENT_COMPONENT: LazyLock = LazyLock::new(|| Component { + base: CosmicColor::new(0.0, 0.0, 0.0, 0.0), + hover: CosmicColor::new(0.0, 0.0, 0.0, 0.0), + pressed: CosmicColor::new(0.0, 0.0, 0.0, 0.0), + selected: CosmicColor::new(0.0, 0.0, 0.0, 0.0), + selected_text: CosmicColor::new(0.0, 0.0, 0.0, 0.0), + focus: CosmicColor::new(0.0, 0.0, 0.0, 0.0), + disabled: CosmicColor::new(0.0, 0.0, 0.0, 0.0), + on: CosmicColor::new(0.0, 0.0, 0.0, 0.0), + on_disabled: CosmicColor::new(0.0, 0.0, 0.0, 0.0), + divider: CosmicColor::new(0.0, 0.0, 0.0, 0.0), + border: CosmicColor::new(0.0, 0.0, 0.0, 0.0), + disabled_border: CosmicColor::new(0.0, 0.0, 0.0, 0.0), +}); pub(crate) static THEME: Mutex = Mutex::new(Theme { theme_type: ThemeType::Dark, diff --git a/src/widget/calendar.rs b/src/widget/calendar.rs index 02b98cf..303a1ed 100644 --- a/src/widget/calendar.rs +++ b/src/widget/calendar.rs @@ -119,22 +119,14 @@ where macro_rules! icon { ($name:expr, $on_press:expr) => {{ #[cfg(target_os = "linux")] - let icon = { - icon::from_name($name) - .apply(button::icon) - }; + let icon = { icon::from_name($name).apply(button::icon) }; #[cfg(not(target_os = "linux"))] let icon = { - icon::from_svg_bytes(include_bytes!(concat!( - "../../res/icons/", - $name, - ".svg" - ))) - .symbolic(true) - .apply(button::icon) + icon::from_svg_bytes(include_bytes!(concat!("../../res/icons/", $name, ".svg"))) + .symbolic(true) + .apply(button::icon) }; - icon.padding([0, 12]) - .on_press($on_press) + icon.padding([0, 12]).on_press($on_press) }}; } let date = text(this.model.visible.format("%B %Y").to_string()).size(18); diff --git a/src/widget/color_picker/mod.rs b/src/widget/color_picker/mod.rs index 789969a..a17625d 100644 --- a/src/widget/color_picker/mod.rs +++ b/src/widget/color_picker/mod.rs @@ -6,6 +6,7 @@ use std::borrow::Cow; use std::iter; use std::rc::Rc; +use std::sync::LazyLock; use std::sync::atomic::{AtomicBool, Ordering}; use std::time::{Duration, Instant}; @@ -26,7 +27,6 @@ use iced_core::{ use iced_widget::slider::HandleShape; use iced_widget::{Row, canvas, column, horizontal_space, row, scrollable, vertical_space}; -use lazy_static::lazy_static; use palette::{FromColor, RgbHue}; use super::divider::horizontal; @@ -38,17 +38,17 @@ use super::{Icon, button, segmented_control, text, text_input, tooltip}; pub use ColorPickerModel as Model; // TODO is this going to look correct enough? -lazy_static! { - pub static ref HSV_RAINBOW: Vec = (0u16..8) - .map( - |h| iced::Color::from(palette::Srgba::from_color(palette::Hsv::new_srgb_const( +pub static HSV_RAINBOW: LazyLock> = LazyLock::new(|| { + (0u16..8) + .map(|h| { + Color::from(palette::Srgba::from_color(palette::Hsv::new_srgb_const( RgbHue::new(f32::from(h) * 360.0 / 7.0), 1.0, - 1.0 + 1.0, ))) - ) - .collect(); -} + }) + .collect() +}); const MAX_RECENT: usize = 20;