summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2024-10-02 11:29:55 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2024-10-02 11:29:55 +1300
commitee52c97191e1243f5ad1909468a5c43b721dffe9 (patch)
tree3670315dc6317d6339b5e8b05ed4fc4a1cc8c2c4 /src/lib.rs
parentd1223e40f75a245ff3984598cb0c786c4d5b8488 (diff)
downloadcolour-ee52c97191e1243f5ad1909468a5c43b721dffe9.zip
Implement the Display trait for Colour
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 64dd321..a265a30 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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()
+ )
}
}