From 6fe46a1085d61dffb8151739ebf9154ce19bd166 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Tue, 18 May 2021 20:17:12 +0100 Subject: [PATCH] simplify --- src/colour.rs | 7 +++---- src/image.rs | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/colour.rs b/src/colour.rs index 58a27f4..78652e0 100644 --- a/src/colour.rs +++ b/src/colour.rs @@ -17,11 +17,10 @@ impl From<&str> for Colour { impl From> for Colour { fn from(colours: Vec) -> Self { - const ZERO: u8 = 0; Colour { - red: *colours.get(0).unwrap_or(&ZERO), - green: *colours.get(1).unwrap_or(&ZERO), - blue: *colours.get(2).unwrap_or(&ZERO), + red: *colours.get(0).unwrap_or(&0), + green: *colours.get(1).unwrap_or(&0), + blue: *colours.get(2).unwrap_or(&0), } } } diff --git a/src/image.rs b/src/image.rs index d1a2ef1..2e6076c 100644 --- a/src/image.rs +++ b/src/image.rs @@ -14,10 +14,9 @@ impl Image { let name = path.file_stem().unwrap().to_str().unwrap().into(); let mut pixels: Vec = Vec::new(); - for line in read_to_string(&path).unwrap().lines() { - for char in line.chars() { - pixels.push(char.to_string().parse().unwrap()); - } + // todo .matches [0..3] instead of replacing whitespace? + for char in read_to_string(&path).unwrap().replace('\n', "").chars() { + pixels.push(char.to_string().parse().unwrap()); } Self { name, pixels }