From 689c60d428f46dc59316eafa22297e196afa4b15 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: Thu, 6 Nov 2025 16:08:48 +0100 Subject: [PATCH] chore: migrate to Rust 2024 and update dependencies --- Cargo.toml | 14 +++++++------- benches/simple_lookup.rs | 4 ++-- src/lib.rs | 12 ++++++------ src/theme/mod.rs | 18 +++--------------- src/theme/parse.rs | 4 ++-- src/theme/paths.rs | 27 +++++++++++++-------------- 6 files changed, 33 insertions(+), 46 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2bea5e6..e14a113 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cosmic-freedesktop-icons" version = "0.4.0" -edition = "2021" +edition = "2024" license = "MIT" description = "A Freedesktop Icons lookup crate" @@ -10,18 +10,18 @@ readme = "README.md" keywords = ["icons", "gui", "freedesktop"] [dependencies] -dirs = "5.0" +dirs = "6.0" thiserror = "2.0" -xdg = "2.5" -tracing = "0.1.0" +xdg = "3.0" +tracing = "0.1.41" ini_core = "0.2.0" memmap2 = "0.9" [dev-dependencies] -speculoos = "0.11.0" +speculoos = "0.13.0" linicon = "2.3.0" -gtk4 = "0.9" -criterion = "0.5" +gtk4 = "0.10" +criterion = "0.7" [features] default = [] diff --git a/benches/simple_lookup.rs b/benches/simple_lookup.rs index 7c83379..8fd6c32 100644 --- a/benches/simple_lookup.rs +++ b/benches/simple_lookup.rs @@ -1,6 +1,6 @@ use criterion::{ - black_box, criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion, - PlotConfiguration, + AxisScale, BenchmarkId, Criterion, PlotConfiguration, black_box, criterion_group, + criterion_main, }; use freedesktop_icons::lookup; use gtk4::{IconLookupFlags, IconTheme, TextDirection}; diff --git a/src/lib.rs b/src/lib.rs index 617660b..2b642e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,8 +53,8 @@ //! ``` use theme::BASE_PATHS; -use crate::cache::{CacheEntry, CACHE}; -use crate::theme::{try_build_icon_path, THEMES}; +use crate::cache::{CACHE, CacheEntry}; +use crate::theme::{THEMES, try_build_icon_path}; use std::io::BufRead; use std::path::PathBuf; use std::time::Instant; @@ -109,7 +109,7 @@ pub fn list_themes() -> Vec { /// /// ## Example /// ```rust, no_run -/// use freedesktop_icons::default_theme_gtk; +/// use cosmic_freedesktop_icons::default_theme_gtk; /// /// let theme = default_theme_gtk(); /// @@ -174,7 +174,7 @@ pub struct LookupBuilder<'a> { /// /// let icon = lookup("firefox").find(); /// # } -pub fn lookup(name: &str) -> LookupBuilder { +pub fn lookup(name: &str) -> LookupBuilder<'_> { LookupBuilder::new(name) } @@ -304,7 +304,7 @@ impl<'a> LookupBuilder<'a> { CacheEntry::NotFound(last_check) if last_check.duration_since(Instant::now()).as_secs() < 5 => { - return None + return None; } _ => (), } @@ -412,7 +412,7 @@ impl<'a> LookupBuilder<'a> { #[cfg(test)] #[cfg(feature = "local_tests")] mod test { - use crate::{lookup, CacheEntry, CACHE}; + use crate::{CACHE, CacheEntry, lookup}; use speculoos::prelude::*; use std::path::PathBuf; diff --git a/src/theme/mod.rs b/src/theme/mod.rs index 99336c8..5e0b1a8 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -130,32 +130,20 @@ fn try_build_svg>(name: &str, path: P) -> Option { let path = path.as_ref(); let svg = path.join(format!("{name}.svg")); - if svg.exists() { - Some(svg) - } else { - None - } + if svg.exists() { Some(svg) } else { None } } fn try_build_png>(name: &str, path: P) -> Option { let path = path.as_ref(); let png = path.join(format!("{name}.png")); - if png.exists() { - Some(png) - } else { - None - } + if png.exists() { Some(png) } else { None } } fn try_build_xmp>(name: &str, path: P) -> Option { let path = path.as_ref(); let xmp = path.join(format!("{name}.xmp")); - if xmp.exists() { - Some(xmp) - } else { - None - } + if xmp.exists() { Some(xmp) } else { None } } // Iter through the base paths and get all theme directories diff --git a/src/theme/parse.rs b/src/theme/parse.rs index c3e223c..01eaa09 100644 --- a/src/theme/parse.rs +++ b/src/theme/parse.rs @@ -1,5 +1,5 @@ -use crate::theme::directories::{Directory, DirectoryType}; use crate::theme::Theme; +use crate::theme::directories::{Directory, DirectoryType}; fn icon_theme_section(file: &str) -> impl Iterator + '_ { ini_core::Parser::new(file) @@ -24,7 +24,7 @@ enum DirectorySection<'a> { Section(&'a str), } -fn sections(file: &str) -> impl Iterator { +fn sections(file: &str) -> impl Iterator> { ini_core::Parser::new(file).filter_map(move |item| match item { ini_core::Item::Property(key, Some(value)) => Some(DirectorySection::Property(key, value)), ini_core::Item::Section(section) => Some(DirectorySection::Section(section)), diff --git a/src/theme/paths.rs b/src/theme/paths.rs index 7d88b00..c4581e6 100644 --- a/src/theme/paths.rs +++ b/src/theme/paths.rs @@ -11,19 +11,18 @@ pub(crate) static BASE_PATHS: LazyLock> = LazyLock::new(icon_theme_ /// Look in $HOME/.icons (for backwards compatibility), in $XDG_DATA_DIRS/icons, in $XDG_DATA_DIRS/pixmaps and in /usr/share/pixmaps (in that order). /// Paths that are not found are filtered out. fn icon_theme_base_paths() -> Vec { - let mut data_dirs: Vec<_> = BaseDirectories::new() - .map(|bd| { - let mut data_dirs: Vec<_> = bd - .get_data_dirs() - .into_iter() - .flat_map(|p| [p.join("icons"), p.join("pixmaps")]) - .collect(); - let data_home = bd.get_data_home(); - data_dirs.push(data_home.join("icons")); - data_dirs.push(data_home.join("pixmaps")); - data_dirs - }) - .unwrap_or_default(); + let base_dirs = BaseDirectories::new(); + let mut data_dirs: Vec<_> = base_dirs + .get_data_dirs() + .into_iter() + .flat_map(|p| [p.join("icons"), p.join("pixmaps")]) + .collect(); + + if let Some(data_home) = base_dirs.get_data_home() { + data_dirs.push(data_home.join("icons")); + data_dirs.push(data_home.join("pixmaps")); + } + match home_dir().map(|home| home.join(".icons")) { Some(home_icon_dir) => data_dirs.push(home_icon_dir), None => tracing::warn!("No $HOME directory found"), @@ -49,7 +48,7 @@ impl ThemePath { #[cfg(test)] mod test { use crate::theme::paths::icon_theme_base_paths; - use crate::theme::{get_all_themes, Theme}; + use crate::theme::{Theme, get_all_themes}; use speculoos::prelude::*; #[test]