use std::fmt;
pub struct Colour {
pub red: u8,
pub green: u8,
pub blue: u8,
pub alpha: u8,
}
impl Colour {
pub fn new(red: u8, green: u8, blue: u8, alpha: u8) -> Colour {
Colour {
red,
green,
blue,
alpha,
}
}
}
impl PartialEq for Colour {
fn eq(&self, other: &Colour) -> bool {
self.red == other.red
&& self.green == other.green
&& self.blue == other.blue
&& self.alpha == other.alpha
}
}
impl Eq for Colour {}
impl fmt::Debug for Colour {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"[red: {}, green: {}, blue: {}, alpha: {}]",
self.red, self.green, self.blue, self.alpha
)
}
}
impl fmt::Display for Colour {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"(red: {}, green: {}, blue: {}, alpha: {})",
self.red, self.green, self.blue, self.alpha
)
}
}
impl Copy for Colour {}
impl Clone for Colour {
fn clone(&self) -> Colour {
*self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn new_test() {
let colour = Colour::new(5, 3, 26, 255);
let result_colour = Colour {
red: 5,
green: 3,
blue: 26,
alpha: 255,
};
assert_eq!(result_colour, colour);
}
}