From da9ab5a1b33c45fd26ac12cc4d1dbba5622d2943 Mon Sep 17 00:00:00 2001 From: Gwen Lg Date: Tue, 16 Jul 2024 22:24:14 +0200 Subject: [PATCH] make dump_images accept iterator on value, not only ref Use Borrow trait allow working on iterator on ImageBuffer in addition to iterator on &ImageBuffer --- src/image/utils.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/image/utils.rs b/src/image/utils.rs index f78fc39..5a2e5f1 100644 --- a/src/image/utils.rs +++ b/src/image/utils.rs @@ -1,6 +1,7 @@ use crate::SubtileError; use image::{EncodableLayout, Pixel, PixelWithColorType}; use std::{ + borrow::Borrow, fs::create_dir_all, io, ops::Deref, @@ -32,12 +33,16 @@ pub enum DumpError { /// Dump some images in a folder specified by the path. #[profiling::function] -pub fn dump_images<'a, Img, P, Container>(path: &str, images: Img) -> Result<(), SubtileError> +pub fn dump_images<'a, Iter, Img, P, Container>( + path: &str, + images: Iter, +) -> Result<(), SubtileError> where P: Pixel + PixelWithColorType + 'a, [P::Subpixel]: EncodableLayout, Container: Deref + 'a, - Img: IntoIterator>, + Img: Borrow>, + Iter: IntoIterator, { let folder_path = PathBuf::from(path); @@ -55,7 +60,7 @@ where .try_for_each(move |(i, img)| { let mut filepath = folder_path.clone(); filepath.push(format!("{i:06}.png")); - dump_image(&filepath, img).map_err(|source| DumpError::DumpImage { + dump_image(&filepath, img.borrow()).map_err(|source| DumpError::DumpImage { filename: filepath, source, })