Skip to content

Commit dea292d

Browse files
committed
Derive thiserror::Error for HexColorError (#2740)
# Objective - Make it easy to use HexColorError with `thiserror`, i.e. converting it into other error types. Makes this possible: ```rust #[derive(Debug, thiserror::Error)] pub enum LdtkError { #[error("An error occured while deserializing")] Json(#[from] serde_json::Error), #[error("An error occured while parsing a color")] HexColor(#[from] bevy::render::color::HexColorError), } ``` ## Solution - Derive thiserror::Error the same way we do elsewhere (see query.rs for instance)
1 parent d4a552a commit dea292d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

crates/bevy_render/src/color.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use bevy_math::{Vec3, Vec4};
1010
use bevy_reflect::{Reflect, ReflectDeserialize};
1111
use serde::{Deserialize, Serialize};
1212
use std::ops::{Add, AddAssign, Mul, MulAssign};
13+
use thiserror::Error;
1314

1415
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
1516
#[reflect(PartialEq, Serialize, Deserialize)]
@@ -1070,10 +1071,12 @@ impl Bytes for Color {
10701071

10711072
impl_render_resource_bytes!(Color);
10721073

1073-
#[derive(Debug)]
1074+
#[derive(Debug, Error)]
10741075
pub enum HexColorError {
1076+
#[error("Unexpected length of hex string")]
10751077
Length,
1076-
Hex(hex::FromHexError),
1078+
#[error("Error parsing hex value")]
1079+
Hex(#[from] hex::FromHexError),
10771080
}
10781081

10791082
fn decode_rgb(data: &[u8]) -> Result<Color, HexColorError> {

0 commit comments

Comments
 (0)