use crate::DocumentError;
#[cfg(feature = "pdf-input")]
#[cfg_attr(docsrs, doc(cfg(feature = "pdf-input")))]
pub mod pdf;
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InputKind {
Png,
Jpeg,
Pdf,
}
impl InputKind {
pub fn detect(path: &std::path::Path) -> Result<Self, DocumentError> {
let ext = path
.extension()
.and_then(|s| s.to_str())
.map(|s| s.to_ascii_lowercase());
match ext.as_deref() {
Some("png") => Ok(Self::Png),
Some("jpg" | "jpeg") => Ok(Self::Jpeg),
Some("pdf") => Ok(Self::Pdf),
_ => Err(DocumentError::UnsupportedInput {
path: path.to_path_buf(),
reason: "extension must be one of: png, jpg, jpeg, pdf",
}),
}
}
pub fn extension(&self) -> &'static str {
match self {
Self::Png => "png",
Self::Jpeg => "jpg",
Self::Pdf => "pdf",
}
}
}