Skip to content

Commit 284e36a

Browse files
Remove thiserror from bevy_color (#15777)
# Objective - Contributes to #15460 ## Solution - Removed `thiserror` from `bevy_color`
1 parent 1be0ed3 commit 284e36a

File tree

3 files changed

+14
-68
lines changed

3 files changed

+14
-68
lines changed

crates/bevy_color/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.15.0-dev", features = [
1616
], optional = true }
1717
bytemuck = { version = "1", features = ["derive"] }
1818
serde = { version = "1.0", features = ["derive"], optional = true }
19-
thiserror = "1.0"
19+
derive_more = { version = "1", default-features = false, features = [
20+
"error",
21+
"from",
22+
"display",
23+
] }
2024
wgpu-types = { version = "22", default-features = false, optional = true }
2125
encase = { version = "0.10", default-features = false }
2226

crates/bevy_color/src/color.rs

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{
44
};
55
#[cfg(feature = "bevy_reflect")]
66
use bevy_reflect::prelude::*;
7+
use derive_more::derive::From;
78

89
/// An enumerated type that can represent any of the color types in this crate.
910
///
@@ -40,7 +41,7 @@ use bevy_reflect::prelude::*;
4041
/// due to its perceptual uniformity and broad support for Bevy's color operations.
4142
/// To avoid the cost of repeated conversion, and ensure consistent results where that is desired,
4243
/// first convert this [`Color`] into your desired color space.
43-
#[derive(Debug, Clone, Copy, PartialEq)]
44+
#[derive(Debug, Clone, Copy, PartialEq, From)]
4445
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(PartialEq, Default))]
4546
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
4647
#[cfg_attr(
@@ -426,66 +427,6 @@ impl Alpha for Color {
426427
}
427428
}
428429

429-
impl From<Srgba> for Color {
430-
fn from(value: Srgba) -> Self {
431-
Self::Srgba(value)
432-
}
433-
}
434-
435-
impl From<LinearRgba> for Color {
436-
fn from(value: LinearRgba) -> Self {
437-
Self::LinearRgba(value)
438-
}
439-
}
440-
441-
impl From<Hsla> for Color {
442-
fn from(value: Hsla) -> Self {
443-
Self::Hsla(value)
444-
}
445-
}
446-
447-
impl From<Hsva> for Color {
448-
fn from(value: Hsva) -> Self {
449-
Self::Hsva(value)
450-
}
451-
}
452-
453-
impl From<Hwba> for Color {
454-
fn from(value: Hwba) -> Self {
455-
Self::Hwba(value)
456-
}
457-
}
458-
459-
impl From<Oklaba> for Color {
460-
fn from(value: Oklaba) -> Self {
461-
Self::Oklaba(value)
462-
}
463-
}
464-
465-
impl From<Oklcha> for Color {
466-
fn from(value: Oklcha) -> Self {
467-
Self::Oklcha(value)
468-
}
469-
}
470-
471-
impl From<Lcha> for Color {
472-
fn from(value: Lcha) -> Self {
473-
Self::Lcha(value)
474-
}
475-
}
476-
477-
impl From<Laba> for Color {
478-
fn from(value: Laba) -> Self {
479-
Self::Laba(value)
480-
}
481-
}
482-
483-
impl From<Xyza> for Color {
484-
fn from(value: Xyza) -> Self {
485-
Self::Xyza(value)
486-
}
487-
}
488-
489430
impl From<Color> for Srgba {
490431
fn from(value: Color) -> Self {
491432
match value {

crates/bevy_color/src/srgba.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
use bevy_math::{ops, Vec3, Vec4};
66
#[cfg(feature = "bevy_reflect")]
77
use bevy_reflect::prelude::*;
8-
use thiserror::Error;
8+
use derive_more::derive::{Display, Error, From};
99

1010
/// Non-linear standard RGB with alpha.
1111
#[doc = include_str!("../docs/conversion.md")]
@@ -421,16 +421,17 @@ impl From<Srgba> for Xyza {
421421
}
422422

423423
/// Error returned if a hex string could not be parsed as a color.
424-
#[derive(Debug, Error, PartialEq, Eq)]
424+
#[derive(Debug, Error, Display, PartialEq, Eq, From)]
425425
pub enum HexColorError {
426426
/// Parsing error.
427-
#[error("Invalid hex string")]
428-
Parse(#[from] core::num::ParseIntError),
427+
#[display("Invalid hex string")]
428+
Parse(core::num::ParseIntError),
429429
/// Invalid length.
430-
#[error("Unexpected length of hex string")]
430+
#[display("Unexpected length of hex string")]
431431
Length,
432432
/// Invalid character.
433-
#[error("Invalid hex char")]
433+
#[display("Invalid hex char")]
434+
#[error(ignore)]
434435
Char(char),
435436
}
436437

0 commit comments

Comments
 (0)