diff options
Diffstat (limited to 'src/picture.rs')
-rw-r--r-- | src/picture.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/picture.rs b/src/picture.rs index f92876c..76a33df 100644 --- a/src/picture.rs +++ b/src/picture.rs @@ -5,6 +5,7 @@ use std::io::{Read, Seek}; use image::io::Reader as ImageReader; use image::error::ImageError; use image::imageops; +use serde::Serialize; use crate::context::Context; @@ -20,11 +21,11 @@ pub enum ConversionError { ImageError(ImageError), } -#[derive(Debug)] +#[derive(Debug, Serialize)] pub struct Picture { - taken: Option<String>, - hash: md5::Digest, - path: PathBuf, + pub taken: Option<String>, + hash: String, + pub path: PathBuf, } pub struct Converter<'a> { @@ -32,7 +33,7 @@ pub struct Converter<'a> { pic: &'a Picture, } -fn hash_reader<R: Read>(reader: &mut R) -> Result<md5::Digest, io::Error> { +fn hash_reader<R: Read>(reader: &mut R) -> Result<String, io::Error> { let mut hash = md5::Context::new(); let mut buff = [0; 1024]; @@ -46,7 +47,7 @@ fn hash_reader<R: Read>(reader: &mut R) -> Result<md5::Digest, io::Error> { hash.consume(&buff[..count]) } - Ok(hash.compute()) + Ok(format!("{:?}", hash.compute())) } impl Picture { @@ -106,7 +107,7 @@ impl Converter<'_> { } pub fn get_size(&mut self, ctx: &Context, size: u32) -> Result<PathBuf, ImageError> { - let hash = md5::compute(format!("{},{},{:?}", size, ctx.options.ext, self.pic.hash)); + let hash = md5::compute(format!("{},{},{}", size, ctx.options.ext, self.pic.hash)); let name = format!("{:?}.{}", hash, ctx.options.ext); let path = ctx.imgdir.join(name); |