diff options
author | Julian T <julian@jtle.dk> | 2021-07-27 17:46:28 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-07-27 17:46:28 +0200 |
commit | f0648bcc4e7a6b7ce3f59013f25413a667dc507a (patch) | |
tree | a204f651e8fabb98953897f4c3b186ac89e57969 /src/main.rs | |
parent | d7244c2cc7b8f62f2f42cca7f3dece89c30bf105 (diff) |
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(()) } |