From a6f3a7b9a5640a0754e1ebf48c1545e62c2c4982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Sat, 30 Dec 2017 02:39:21 +0100 Subject: [PATCH] Check if the input image exists --- src/main.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index c1c15c9..a6bd7f8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -164,7 +164,10 @@ fn load_image(path: &str, size: &(u32, u32)) -> DynamicImage { // Create a path instance let path = Path::new(&path); - // TODO: make sure the path exists. + // Check whether the path exists + if !path.is_file(path) { + panic!("The given path does not exist or is not a file"); + } // Load the image println!("Loading image..."); @@ -371,7 +374,7 @@ impl PixClient { // let size = self // .write_read_command("SIZE".into()) // .expect("Failed to read screen size"); - + // // // TODO: Remove this after debugging // println!("Read size: {}", size); // } @@ -390,13 +393,13 @@ impl PixClient { // fn write_read_command(&mut self, cmd: String) -> Result { // // Write the command // self.write_command(cmd); - + // // // Read the output // let mut buffer = String::with_capacity(CMD_READ_BUFFER_SIZE); // println!("Reading line..."); // self.stream.read_line(&mut buffer)?; // println!("Done reading"); - + // // // Return the read string // Ok(buffer) // }