From 67567529ec37a005d4c559865c21e2d5838654d7 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Wed, 6 May 2026 22:37:04 +0700 Subject: [PATCH] Update to Rust 2024 edition --- Cargo.toml | 2 +- color/examples/gradient.rs | 2 +- color/make_x11_colors.py | 6 +----- color/src/cache_key.rs | 2 +- color/src/color.rs | 6 +++--- color/src/colorspace.rs | 2 +- color/src/dynamic.rs | 6 +++--- color/src/impl_bytemuck.rs | 10 +++++----- color/src/lib.rs | 4 ++-- color/src/parse.rs | 14 +++++++++----- color/src/serialize.rs | 11 ++++------- color/src/x11_colors.rs | 6 +----- 12 files changed, 32 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a9c020d..30276ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ members = ["color", "color_operations"] # version in the `workspace.dependencies` section in this file. version = "0.3.3" -edition = "2021" +edition = "2024" # Keep in sync with RUST_MIN_VER in .github/workflows/ci.yml, with the relevant README.md files # and with the MSRV in the `Unreleased` section of CHANGELOG.md. rust-version = "1.86" diff --git a/color/examples/gradient.rs b/color/examples/gradient.rs index 5171e6b..7bc76c7 100644 --- a/color/examples/gradient.rs +++ b/color/examples/gradient.rs @@ -11,7 +11,7 @@ //! cargo run --example gradient 'oklab(0.5 0.2 0)' 'rgb(0, 200, 0, 0.8)' oklab //! ``` -use color::{gradient, ColorSpaceTag, DynamicColor, GradientIter, HueDirection, Srgb}; +use color::{ColorSpaceTag, DynamicColor, GradientIter, HueDirection, Srgb, gradient}; fn main() { let mut args = std::env::args().skip(1); diff --git a/color/make_x11_colors.py b/color/make_x11_colors.py index a407bc8..9d638f4 100644 --- a/color/make_x11_colors.py +++ b/color/make_x11_colors.py @@ -273,9 +273,5 @@ def minimal_perfect_hash(d): } let salt = SALTS[weak_hash(key, 0, SALTS.len())] as u32; let ix = weak_hash(key, salt, SALTS.len()); - if s == NAMES[ix] { - Some(ix) - } else { - None - } + if s == NAMES[ix] { Some(ix) } else { None } }""") diff --git a/color/src/cache_key.rs b/color/src/cache_key.rs index ed79b3b..6dfdf0f 100644 --- a/color/src/cache_key.rs +++ b/color/src/cache_key.rs @@ -177,7 +177,7 @@ impl BitEq for &T { mod tests { extern crate std; use super::CacheKey; - use crate::{parse_color, DynamicColor}; + use crate::{DynamicColor, parse_color}; use std::collections::HashMap; #[test] diff --git a/color/src/color.rs b/color/src/color.rs index f8cfd4f..e5fef4e 100644 --- a/color/src/color.rs +++ b/color/src/color.rs @@ -7,8 +7,8 @@ use core::any::TypeId; use core::marker::PhantomData; use crate::{ - cache_key::{BitEq, BitHash}, ColorSpace, ColorSpaceLayout, ColorSpaceTag, Oklab, Oklch, PremulRgba8, Rgba8, Srgb, + cache_key::{BitEq, BitHash}, }; #[cfg(all(not(feature = "std"), not(test)))] @@ -969,8 +969,8 @@ mod tests { extern crate alloc; use super::{ - fast_round_to_u8, fixup_hue, AlphaColor, HueDirection, PremulColor, PremulRgba8, Rgba8, - Srgb, + AlphaColor, HueDirection, PremulColor, PremulRgba8, Rgba8, Srgb, fast_round_to_u8, + fixup_hue, }; #[test] diff --git a/color/src/colorspace.rs b/color/src/colorspace.rs index 8c2ba4d..efce59e 100644 --- a/color/src/colorspace.rs +++ b/color/src/colorspace.rs @@ -6,7 +6,7 @@ extern crate std; use core::any::TypeId; -use crate::{matvecmul, tag::ColorSpaceTag, Chromaticity}; +use crate::{Chromaticity, matvecmul, tag::ColorSpaceTag}; #[cfg(all(not(feature = "std"), not(test)))] use crate::floatfuncs::FloatFuncs; diff --git a/color/src/dynamic.rs b/color/src/dynamic.rs index 19759ff..6733838 100644 --- a/color/src/dynamic.rs +++ b/color/src/dynamic.rs @@ -4,10 +4,10 @@ //! CSS colors and syntax. use crate::{ - cache_key::{BitEq, BitHash}, - color::{add_alpha, fixup_hues_for_interpolate, split_alpha, InterpolationAlphaSpace}, AlphaColor, Chromaticity, ColorSpace, ColorSpaceLayout, ColorSpaceTag, Flags, HueDirection, LinearSrgb, Missing, + cache_key::{BitEq, BitHash}, + color::{InterpolationAlphaSpace, add_alpha, fixup_hues_for_interpolate, split_alpha}, }; use core::hash::{Hash, Hasher}; @@ -650,7 +650,7 @@ impl UnpremultipliedInterpolator { #[cfg(test)] mod tests { - use crate::{parse_color, ColorSpaceTag, DynamicColor, Missing}; + use crate::{ColorSpaceTag, DynamicColor, Missing, parse_color}; // `DynamicColor` was carefully packed. Ensure its size doesn't accidentally change. const _: () = if size_of::() != 20 { diff --git a/color/src/impl_bytemuck.rs b/color/src/impl_bytemuck.rs index 73de3eb..e155858 100644 --- a/color/src/impl_bytemuck.rs +++ b/color/src/impl_bytemuck.rs @@ -4,8 +4,8 @@ #![expect(unsafe_code, reason = "unsafe is required for bytemuck unsafe impls")] use crate::{ - cache_key::CacheKey, AlphaColor, ColorSpace, ColorSpaceTag, HueDirection, OpaqueColor, - PremulColor, PremulRgba8, Rgba8, + AlphaColor, ColorSpace, ColorSpaceTag, HueDirection, OpaqueColor, PremulColor, PremulRgba8, + Rgba8, cache_key::CacheKey, }; // Safety: The struct is `repr(transparent)` and the data member is bytemuck::Pod. @@ -103,10 +103,10 @@ unsafe impl bytemuck::TransparentWrapper for CacheKey {} #[cfg(test)] mod tests { use crate::{ - cache_key::CacheKey, AlphaColor, ColorSpaceTag, HueDirection, OpaqueColor, PremulColor, - PremulRgba8, Rgba8, Srgb, + AlphaColor, ColorSpaceTag, HueDirection, OpaqueColor, PremulColor, PremulRgba8, Rgba8, + Srgb, cache_key::CacheKey, }; - use bytemuck::{checked::try_from_bytes, Contiguous, TransparentWrapper, Zeroable}; + use bytemuck::{Contiguous, TransparentWrapper, Zeroable, checked::try_from_bytes}; use core::{marker::PhantomData, ptr}; fn assert_is_pod(_pod: impl bytemuck::Pod) {} diff --git a/color/src/lib.rs b/color/src/lib.rs index c98f94e..a7fbb20 100644 --- a/color/src/lib.rs +++ b/color/src/lib.rs @@ -117,8 +117,8 @@ pub use colorspace::{ }; pub use dynamic::{DynamicColor, Interpolator, UnpremultipliedInterpolator}; pub use flags::{Flags, Missing}; -pub use gradient::{gradient, gradient_unpremultiplied, GradientIter, UnpremultipliedGradientIter}; -pub use parse::{parse_color, parse_color_prefix, ParseError}; +pub use gradient::{GradientIter, UnpremultipliedGradientIter, gradient, gradient_unpremultiplied}; +pub use parse::{ParseError, parse_color, parse_color_prefix}; pub use rgba8::{PremulRgba8, Rgba8}; pub use tag::ColorSpaceTag; diff --git a/color/src/parse.rs b/color/src/parse.rs index 718bc6c..61e2cbc 100644 --- a/color/src/parse.rs +++ b/color/src/parse.rs @@ -709,7 +709,7 @@ fn make_lowercase<'a>(s: &'a str, buf: &'a mut [u8; LOWERCASE_BUF_SIZE]) -> &'a mod tests { use crate::DynamicColor; - use super::{parse_color, parse_color_prefix, Mode, ParseError, Parser}; + use super::{Mode, ParseError, Parser, parse_color, parse_color_prefix}; fn assert_close_color(c1: DynamicColor, c2: DynamicColor) { const EPSILON: f32 = 1e-4; @@ -797,8 +797,10 @@ mod tests { ] { let mut parser = Parser::new(alpha); let result = parser.alpha(mode); - assert_eq!(result, expected, - "Failed parsing specified alpha `{alpha}`. Expected: `{expected:?}`. Got: `{result:?}`."); + assert_eq!( + result, expected, + "Failed parsing specified alpha `{alpha}`. Expected: `{expected:?}`. Got: `{result:?}`." + ); } } @@ -812,8 +814,10 @@ mod tests { ] { let mut parser = Parser::new(angle); let result = parser.angle().unwrap().unwrap(); - assert!((result - expected).abs() < 1e-4, - "Failed parsing specified angle `{angle}`. Expected: `{expected:?}`. Got: `{result:?}`."); + assert!( + (result - expected).abs() < 1e-4, + "Failed parsing specified angle `{angle}`. Expected: `{expected:?}`. Got: `{result:?}`." + ); } { diff --git a/color/src/serialize.rs b/color/src/serialize.rs index 3de751e..0522d2f 100644 --- a/color/src/serialize.rs +++ b/color/src/serialize.rs @@ -152,7 +152,7 @@ impl core::fmt::UpperHex for Rgba8 { mod tests { extern crate alloc; - use crate::{parse_color, AlphaColor, DynamicColor, Hsl, Oklab, Srgb, XyzD65}; + use crate::{AlphaColor, DynamicColor, Hsl, Oklab, Srgb, XyzD65, parse_color}; use alloc::format; #[test] @@ -187,8 +187,7 @@ mod tests { ] { let result = format!("{}", parse_color(specified).unwrap()); assert_eq!( - result, - expected, + result, expected, "Failed serializing specified color `{specified}`. Expected: `{expected}`. Got: `{result}`." ); } @@ -234,8 +233,7 @@ mod tests { ] { let result = format!("{color}"); assert_eq!( - result, - expected, + result, expected, "Failed serializing specified color `{color}`. Expected: `{expected}`. Got: `{result}`." ); } @@ -246,8 +244,7 @@ mod tests { for name in crate::x11_colors::NAMES { let result = format!("{}", parse_color(name).unwrap()); assert_eq!( - result, - name, + result, name, "Failed serializing specified named color `{name}`. Expected it to roundtrip. Got: `{result}`." ); } diff --git a/color/src/x11_colors.rs b/color/src/x11_colors.rs index 6356051..c2e4def 100644 --- a/color/src/x11_colors.rs +++ b/color/src/x11_colors.rs @@ -325,9 +325,5 @@ pub(crate) fn lookup_palette_index(s: &str) -> Option { } let salt = SALTS[weak_hash(key, 0, SALTS.len())] as u32; let ix = weak_hash(key, salt, SALTS.len()); - if s == NAMES[ix] { - Some(ix) - } else { - None - } + if s == NAMES[ix] { Some(ix) } else { None } }