small rebase to reduce used memory

This commit is contained in:
Djairo Hougee 2023-02-08 22:27:52 +01:00
parent 0809baf323
commit 1af68a1a74
2 changed files with 11 additions and 11 deletions

View File

@ -61,14 +61,14 @@ impl Cli {
debug!("braille: {}", self.braille); debug!("braille: {}", self.braille);
debug!("debug: {}", self.debug); debug!("debug: {}", self.debug);
debug!("full: {}", self.full); debug!("full: {}", self.full);
if let Some(map) = self.map.clone() { if let Some(map) = &self.map {
debug!("map: \"{}\"", map); debug!("map: \"{}\"", map);
} else { } else {
debug!("map: None"); debug!("map: None");
} }
debug!("width: {}", self.width.unwrap_or(u32::MAX)); debug!("width: {}", self.width.unwrap_or(u32::MAX));
debug!("image: {}", self.image.display()); debug!("image: {}", self.image.display());
if let Some(output) = self.output.clone() { if let Some(output) = &self.output {
debug!("output: {}", output.display()); debug!("output: {}", output.display());
} else { } else {
debug!("output: None"); debug!("output: None");
@ -76,24 +76,24 @@ impl Cli {
} }
pub fn validate(&self) { pub fn validate(&self) {
if !file_exists(self.image.clone()) { if !file_exists(&self.image) {
error!("Input file \"{}\" does not exist!", self.image.display()); error!("Input file \"{}\" does not exist!", self.image.display());
exit(1); exit(1);
} }
if !is_image(self.image.clone()) { if !is_image(&self.image) {
error!("Input file \"{}\" is not an image!", self.image.display()); error!("Input file \"{}\" is not an image!", self.image.display());
exit(1); exit(1);
} }
if let Some(output) = self.output.clone() { if let Some(output) = &self.output {
if file_exists(output.clone()) { if file_exists(&output) {
error!("Output file \"{}\" already exists!", output.display()); error!("Output file \"{}\" already exists!", output.display());
exit(1); exit(1);
} }
} }
if let Some(map) = self.map.clone() { if let Some(map) = &self.map {
if !map.is_ascii() { if !map.is_ascii() {
error!("map can not contain non-ASCII characters!"); error!("map can not contain non-ASCII characters!");
exit(1); exit(1);
@ -111,11 +111,11 @@ impl Cli {
/// This function checks if a given file is an image /// This function checks if a given file is an image
/// ///
/// arguments: /// arguments:
/// path: PathBuf - path to the file to check /// path: &PathBuf - path to the file to check
/// ///
/// returns: /// returns:
/// boolean indicating if file is an image or not /// 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(); let ext = path.extension();
match ext { match ext {
Some(ext) => { Some(ext) => {
@ -132,11 +132,11 @@ fn is_image(path: PathBuf) -> bool {
/// This function checks if a given file exists /// This function checks if a given file exists
/// ///
/// arguments: /// arguments:
/// path: PathBuf - path to the file to check /// path: &PathBuf - path to the file to check
/// ///
/// returns: /// returns:
/// boolean indicating if the file exists or not /// boolean indicating if the file exists or not
fn file_exists(path: PathBuf) -> bool { fn file_exists(path: &PathBuf) -> bool {
match path.try_exists() { match path.try_exists() {
Ok(bool) => bool, Ok(bool) => bool,
Err(e) => { Err(e) => {

View File