From f16c952f3f23f63d1488babacdf12b408b8e4afd Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 10 Nov 2021 19:33:17 +0100 Subject: turn Palette into newtype --- src/vtcol.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/vtcol.rs b/src/vtcol.rs index 6a51b49..90aca21 100644 --- a/src/vtcol.rs +++ b/src/vtcol.rs @@ -330,17 +330,14 @@ static DUMMY_COLORS: RawPalette = [ "000000", "ffffff", ]; -pub struct Palette -{ - colors: [u8; PALETTE_BYTES], -} +pub struct Palette([u8; PALETTE_BYTES]); impl Palette { fn dump(&self) { let mut buf: [u8; 3] = [0u8, 0u8, 0u8]; - for (i, col) in self.colors.iter().enumerate() { + for (i, col) in self.0.iter().enumerate() { let idx: usize = i % 3; buf[idx] = *col; if idx == 2 { @@ -397,7 +394,7 @@ impl Palette idx += 3; } - Palette { colors: pal } + Palette (pal) } /* [Palette::new] */ @@ -445,7 +442,7 @@ impl Palette line.truncate(0); } - Palette { colors: pal } + Palette (pal) } /* [Palette::from_buffered_reader] */ @@ -487,9 +484,9 @@ impl fmt::Display for Palette let mut i = 0; while i < PALETTE_BYTES { let _ = write!(f, "{}", if i == 0 { "(" } else { "\n " }); - let r = self.colors[i]; - let g = self.colors[i + 1]; - let b = self.colors[i + 2]; + let r = self.0[i]; + let g = self.0[i + 1]; + let b = self.0[i + 2]; let _ = write!( f, "((r 0x{:02.X}) (g 0x{:02.X}) (b 0x{:02.x}))", @@ -507,9 +504,9 @@ impl fmt::Debug for Palette { let mut i: u8 = 0_u8; while (i as usize) < PALETTE_BYTES { - let r = self.colors[i as usize]; - let g = self.colors[i as usize + 1]; - let b = self.colors[i as usize + 2]; + let r = self.0[i as usize]; + let g = self.0[i as usize + 1]; + let b = self.0[i as usize + 2]; let _ = writeln!( f, "{} => 0x{:02.X}{:02.X}{:02.X}", -- cgit v1.2.3