diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index b647cdc..40b1faf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,20 +2,26 @@ mod context; mod picture; mod piece; +use std::error::Error; + use context::Context; use picture::Picture; use piece::Piece; -fn main() { +fn main() -> Result<(), Box<dyn Error>> { println!("Hello, world!"); - let ctx = Context::new_with_args().unwrap(); + let ctx = Context::new_with_args()?; - let pieces = ctx.get_image_files().unwrap().iter() - .map(|file| Picture::new_from_file(&file).unwrap()) - .map(|pic| Piece::new(&ctx, pic).unwrap()) - .collect::<Vec<Piece>>(); + let mut pieces = ctx.get_image_files()?.iter() + .map(|file| -> Result<Piece, Box<dyn Error>> { + let pic = Picture::new_from_file(&file)?; + Ok(Piece::new(&ctx, pic)?) + }).collect::<Result<Vec<Piece>, Box<dyn Error>>>()?; + pieces.sort(); + pieces.reverse(); - piece::create_index(&ctx, &pieces[..]).unwrap(); + piece::create_index(&ctx, &pieces[..])?; + Ok(()) } |