Derive copy for RgbaColor and change debug representation 🐞

This commit is contained in:
Laurenz 2020-07-16 16:27:18 +02:00
parent 0fd327bbc9
commit 6f1319e91f

View File

@ -115,7 +115,7 @@ impl Debug for Ident {
/// [box: background=#423abaff] /// [box: background=#423abaff]
/// ^^^^^^^^ /// ^^^^^^^^
/// ``` /// ```
#[derive(Clone, Eq, PartialEq, Hash)] #[derive(Copy, Clone, Eq, PartialEq, Hash)]
pub struct RgbaColor { pub struct RgbaColor {
/// Red channel. /// Red channel.
pub r: u8, pub r: u8,
@ -141,7 +141,6 @@ impl RgbaColor {
pub fn new_healed(r: u8, g: u8, b: u8, a: u8) -> RgbaColor { pub fn new_healed(r: u8, g: u8, b: u8, a: u8) -> RgbaColor {
RgbaColor { r, g, b, a, healed: true } RgbaColor { r, g, b, a, healed: true }
} }
} }
impl FromStr for RgbaColor { impl FromStr for RgbaColor {
@ -186,21 +185,20 @@ impl FromStr for RgbaColor {
impl Debug for RgbaColor { impl Debug for RgbaColor {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter) -> fmt::Result {
if f.alternate() { if f.alternate() {
f.write_str("rgba(")?; write!(
write!(f, "r: {:02}, ", self.r)?; f,
write!(f, "g: {:02}, ", self.g)?; "rgba({:02}, {:02}, {:02}, {:02})",
write!(f, "b: {:02}, ", self.b)?; self.r, self.g, self.b, self.a,
write!(f, "a: {:02}", self.a)?; )?;
f.write_char(')')?;
} else { } else {
f.write_char('#')?; write!(
write!(f, "{:02x}", self.r)?; f,
write!(f, "{:02x}", self.g)?; "#{:02x}{:02x}{:02x}{:02x}",
write!(f, "{:02x}", self.b)?; self.r, self.g, self.b, self.a,
write!(f, "{:02x}", self.a)?; )?;
} }
if self.healed { if self.healed {
f.write_fmt(format_args!(" [healed]"))?; f.write_str(" [healed]")?;
} }
Ok(()) Ok(())
} }