summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2021-11-10 19:33:17 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2021-11-10 18:45:43 +0100
commitf16c952f3f23f63d1488babacdf12b408b8e4afd (patch)
treed0596773c56b8bc6064232d99f584ba6c1f2b43c
parentf906287746e7e1a837c541c5f4f6668409000187 (diff)
downloadvtcol-f16c952f3f23f63d1488babacdf12b408b8e4afd.tar.gz
turn Palette into newtype
-rw-r--r--src/vtcol.rs23
1 files 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}",