use core::fmt::{self, Debug, LowerHex, UpperHex};
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
}
impl Color {
pub fn as_tuple(&self) -> (u8, u8, u8) {
(self.r, self.g, self.b)
}
pub fn into_tuple(self) -> (u8, u8, u8) {
self.as_tuple()
}
pub fn as_array(&self) -> [u8; 3] {
[self.r, self.g, self.b]
}
pub fn into_array(self) -> [u8; 3] {
self.as_array()
}
}
#[allow(clippy::derivable_impls)] impl Default for Color {
fn default() -> Self {
Color { r: 0, g: 0, b: 0 }
}
}
impl Debug for Color {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Color(#{:x})", self)
}
}
impl LowerHex for Color {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:02x}{:02x}{:02x}", self.r, self.g, self.b)
}
}
impl UpperHex for Color {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:02X}{:02X}{:02X}", self.r, self.g, self.b)
}
}