From 1af68a1a74b96adc3290a34bd93a04e679bc426d Mon Sep 17 00:00:00 2001 From: djairoh Date: Wed, 8 Feb 2023 22:27:52 +0100 Subject: [PATCH] small rebase to reduce used memory --- src/cli.rs | 22 +++++++++++----------- src/mod.rs | 0 2 files changed, 11 insertions(+), 11 deletions(-) delete mode 100644 src/mod.rs diff --git a/src/cli.rs b/src/cli.rs index b541c29..6e5e209 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -61,14 +61,14 @@ impl Cli { debug!("braille: {}", self.braille); debug!("debug: {}", self.debug); debug!("full: {}", self.full); - if let Some(map) = self.map.clone() { + if let Some(map) = &self.map { debug!("map: \"{}\"", map); } else { debug!("map: None"); } debug!("width: {}", self.width.unwrap_or(u32::MAX)); debug!("image: {}", self.image.display()); - if let Some(output) = self.output.clone() { + if let Some(output) = &self.output { debug!("output: {}", output.display()); } else { debug!("output: None"); @@ -76,24 +76,24 @@ impl Cli { } pub fn validate(&self) { - if !file_exists(self.image.clone()) { + if !file_exists(&self.image) { error!("Input file \"{}\" does not exist!", self.image.display()); exit(1); } - if !is_image(self.image.clone()) { + if !is_image(&self.image) { error!("Input file \"{}\" is not an image!", self.image.display()); exit(1); } - if let Some(output) = self.output.clone() { - if file_exists(output.clone()) { + if let Some(output) = &self.output { + if file_exists(&output) { error!("Output file \"{}\" already exists!", output.display()); exit(1); } } - if let Some(map) = self.map.clone() { + if let Some(map) = &self.map { if !map.is_ascii() { error!("map can not contain non-ASCII characters!"); exit(1); @@ -111,11 +111,11 @@ impl Cli { /// This function checks if a given file is an image /// /// arguments: -/// path: PathBuf - path to the file to check +/// path: &PathBuf - path to the file to check /// /// returns: /// boolean indicating if file is an image or not -fn is_image(path: PathBuf) -> bool { +fn is_image(path: &PathBuf) -> bool { let ext = path.extension(); match ext { Some(ext) => { @@ -132,11 +132,11 @@ fn is_image(path: PathBuf) -> bool { /// This function checks if a given file exists /// /// arguments: -/// path: PathBuf - path to the file to check +/// path: &PathBuf - path to the file to check /// /// returns: /// boolean indicating if the file exists or not -fn file_exists(path: PathBuf) -> bool { +fn file_exists(path: &PathBuf) -> bool { match path.try_exists() { Ok(bool) => bool, Err(e) => { diff --git a/src/mod.rs b/src/mod.rs deleted file mode 100644 index e69de29..0000000