From 284e36af5ec04752d0d039191a2ad160521a3cf0 Mon Sep 17 00:00:00 2001 From: Zachary Harrold Date: Thu, 10 Oct 2024 01:18:41 +1100 Subject: [PATCH] Remove `thiserror` from `bevy_color` (#15777) # Objective - Contributes to #15460 ## Solution - Removed `thiserror` from `bevy_color` --- crates/bevy_color/Cargo.toml | 6 +++- crates/bevy_color/src/color.rs | 63 ++-------------------------------- crates/bevy_color/src/srgba.rs | 13 +++---- 3 files changed, 14 insertions(+), 68 deletions(-) diff --git a/crates/bevy_color/Cargo.toml b/crates/bevy_color/Cargo.toml index 27f0e5bdbe..d4854010cb 100644 --- a/crates/bevy_color/Cargo.toml +++ b/crates/bevy_color/Cargo.toml @@ -16,7 +16,11 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.15.0-dev", features = [ ], optional = true } bytemuck = { version = "1", features = ["derive"] } serde = { version = "1.0", features = ["derive"], optional = true } -thiserror = "1.0" +derive_more = { version = "1", default-features = false, features = [ + "error", + "from", + "display", +] } wgpu-types = { version = "22", default-features = false, optional = true } encase = { version = "0.10", default-features = false } diff --git a/crates/bevy_color/src/color.rs b/crates/bevy_color/src/color.rs index 92fa2b98fd..6af43893a6 100644 --- a/crates/bevy_color/src/color.rs +++ b/crates/bevy_color/src/color.rs @@ -4,6 +4,7 @@ use crate::{ }; #[cfg(feature = "bevy_reflect")] use bevy_reflect::prelude::*; +use derive_more::derive::From; /// An enumerated type that can represent any of the color types in this crate. /// @@ -40,7 +41,7 @@ use bevy_reflect::prelude::*; /// due to its perceptual uniformity and broad support for Bevy's color operations. /// To avoid the cost of repeated conversion, and ensure consistent results where that is desired, /// first convert this [`Color`] into your desired color space. -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, From)] #[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(PartialEq, Default))] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr( @@ -426,66 +427,6 @@ impl Alpha for Color { } } -impl From for Color { - fn from(value: Srgba) -> Self { - Self::Srgba(value) - } -} - -impl From for Color { - fn from(value: LinearRgba) -> Self { - Self::LinearRgba(value) - } -} - -impl From for Color { - fn from(value: Hsla) -> Self { - Self::Hsla(value) - } -} - -impl From for Color { - fn from(value: Hsva) -> Self { - Self::Hsva(value) - } -} - -impl From for Color { - fn from(value: Hwba) -> Self { - Self::Hwba(value) - } -} - -impl From for Color { - fn from(value: Oklaba) -> Self { - Self::Oklaba(value) - } -} - -impl From for Color { - fn from(value: Oklcha) -> Self { - Self::Oklcha(value) - } -} - -impl From for Color { - fn from(value: Lcha) -> Self { - Self::Lcha(value) - } -} - -impl From for Color { - fn from(value: Laba) -> Self { - Self::Laba(value) - } -} - -impl From for Color { - fn from(value: Xyza) -> Self { - Self::Xyza(value) - } -} - impl From for Srgba { fn from(value: Color) -> Self { match value { diff --git a/crates/bevy_color/src/srgba.rs b/crates/bevy_color/src/srgba.rs index 53c66a0975..8fdecc19ad 100644 --- a/crates/bevy_color/src/srgba.rs +++ b/crates/bevy_color/src/srgba.rs @@ -5,7 +5,7 @@ use crate::{ use bevy_math::{ops, Vec3, Vec4}; #[cfg(feature = "bevy_reflect")] use bevy_reflect::prelude::*; -use thiserror::Error; +use derive_more::derive::{Display, Error, From}; /// Non-linear standard RGB with alpha. #[doc = include_str!("../docs/conversion.md")] @@ -421,16 +421,17 @@ impl From for Xyza { } /// Error returned if a hex string could not be parsed as a color. -#[derive(Debug, Error, PartialEq, Eq)] +#[derive(Debug, Error, Display, PartialEq, Eq, From)] pub enum HexColorError { /// Parsing error. - #[error("Invalid hex string")] - Parse(#[from] core::num::ParseIntError), + #[display("Invalid hex string")] + Parse(core::num::ParseIntError), /// Invalid length. - #[error("Unexpected length of hex string")] + #[display("Unexpected length of hex string")] Length, /// Invalid character. - #[error("Invalid hex char")] + #[display("Invalid hex char")] + #[error(ignore)] Char(char), }