use crate::detect::Format;
use crate::formats::MetadataHandler;
use crate::formats::jpeg::JpegHandler;
use crate::formats::pdf::PdfHandler;
use crate::formats::png::PngHandler;
use crate::formats::webp::WebpHandler;
#[must_use]
pub fn handler_for(format: Format) -> Option<&'static dyn MetadataHandler> {
match format {
Format::Jpeg => Some(&JpegHandler),
Format::Pdf => Some(&PdfHandler),
Format::Png => Some(&PngHandler),
Format::Webp => Some(&WebpHandler),
}
}
#[must_use]
pub fn supported_formats() -> Vec<Format> {
[Format::Jpeg, Format::Png, Format::Webp, Format::Pdf]
.into_iter()
.filter(|f| handler_for(*f).is_some())
.collect()
}
#[cfg(test)]
mod tests {
#![allow(clippy::expect_used)]
use super::*;
#[test]
fn a_handler_is_registered_for_its_own_format() {
for format in supported_formats() {
let handler = handler_for(format).expect("listed as supported");
assert_eq!(handler.format(), format);
assert_eq!(
handler.name(),
format.id(),
"the handler name is the format id, because both appear in JSON output"
);
}
}
#[test]
fn every_phase_one_format_has_a_handler() {
for format in [Format::Jpeg, Format::Png, Format::Webp, Format::Pdf] {
assert!(handler_for(format).is_some(), "{format} has no handler");
}
}
}