diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2024-10-02 11:29:55 +1300 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2024-10-02 11:29:55 +1300 |
commit | ee52c97191e1243f5ad1909468a5c43b721dffe9 (patch) | |
tree | 3670315dc6317d6339b5e8b05ed4fc4a1cc8c2c4 /src/lib.rs | |
parent | d1223e40f75a245ff3984598cb0c786c4d5b8488 (diff) | |
download | colour-ee52c97191e1243f5ad1909468a5c43b721dffe9.zip |
Implement the Display trait for Colour
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -140,13 +140,24 @@ impl AsRef<u32> for Colour { impl std::fmt::Debug for Colour { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { - let string: &str = &format!( - "Colour {{ r:{} g:{} b:{} a:{}}}", + write!(f, + "Colour {{ r:{} g:{} b:{}, a:{} }}", self.red(), self.green(), self.blue(), self.alpha() - ); - f.write_str(string) + ) + } +} + +impl std::fmt::Display for Colour { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + write!(f, + "#{:02x}{:02x}{:02x}{:02x}", + self.red(), + self.green(), + self.blue(), + self.alpha() + ) } } |