semdiff_differ_image/
report_summary.rs1use crate::{ImageDiff, ImageDiffReporter, image_format};
2use semdiff_core::fs::FileLeaf;
3use semdiff_core::{DetailReporter, MayUnsupported};
4use semdiff_output::summary::SummaryReport;
5use std::convert;
6
7impl<W> DetailReporter<ImageDiff, FileLeaf, SummaryReport<W>> for ImageDiffReporter {
8 type Error = convert::Infallible;
9
10 fn report_unchanged(
11 &self,
12 _name: &str,
13 _diff: ImageDiff,
14 reporter: &SummaryReport<W>,
15 ) -> Result<MayUnsupported<()>, Self::Error> {
16 reporter.increment_unchanged();
17 Ok(MayUnsupported::Ok(()))
18 }
19
20 fn report_modified(
21 &self,
22 _name: &str,
23 _diff: ImageDiff,
24 reporter: &SummaryReport<W>,
25 ) -> Result<MayUnsupported<()>, Self::Error> {
26 reporter.increment_modified();
27 Ok(MayUnsupported::Ok(()))
28 }
29
30 fn report_added(
31 &self,
32 _name: &str,
33 data: FileLeaf,
34 reporter: &SummaryReport<W>,
35 ) -> Result<MayUnsupported<()>, Self::Error> {
36 if image_format(&data.kind)
37 .is_none_or(|format| image::load_from_memory_with_format(&data.content, format).is_err())
38 {
39 return Ok(MayUnsupported::Unsupported);
40 }
41 reporter.increment_added();
42 Ok(MayUnsupported::Ok(()))
43 }
44
45 fn report_deleted(
46 &self,
47 _name: &str,
48 data: FileLeaf,
49 reporter: &SummaryReport<W>,
50 ) -> Result<MayUnsupported<()>, Self::Error> {
51 if image_format(&data.kind)
52 .is_none_or(|format| image::load_from_memory_with_format(&data.content, format).is_err())
53 {
54 return Ok(MayUnsupported::Unsupported);
55 }
56 reporter.increment_deleted();
57 Ok(MayUnsupported::Ok(()))
58 }
59}