chore: refactor ahead of supporting more conversion types
All checks were successful
Checking Renovate configuration / validate (pull_request) Successful in 1m5s
Build and test / Clippy (pull_request) Successful in 3m25s
Checking yaml / Run yamllint (pull_request) Successful in 11s
Build and test / Tests (pull_request) Successful in 4m12s
Build and test / Build AMD64 (pull_request) Successful in 4m12s
Build and test / Generate Documentation (pull_request) Successful in 3m52s

This commit is contained in:
Marc Plano-Lesay 2025-10-10 16:34:52 +11:00
parent 48b560d85e
commit 034f0b142c
Signed by: kernald
GPG key ID: 66A41B08CC62A6CF
12 changed files with 468 additions and 150 deletions

49
src/formats/mod.rs Normal file
View file

@ -0,0 +1,49 @@
use std::ffi::OsStr;
use std::path::Path;
use anyhow::Result;
use crate::model::Document;
pub mod cbz;
pub mod pdf;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FormatId {
Cbz,
Pdf,
}
impl FormatId {
#[allow(dead_code)]
pub fn can_read(self) -> bool {
match self {
FormatId::Cbz => true,
FormatId::Pdf => false, // planned but not implemented yet
}
}
#[allow(dead_code)]
pub fn can_write(self) -> bool {
match self {
FormatId::Pdf => true,
FormatId::Cbz => false, // planned but not implemented yet
}
}
pub fn detect_from_path(path: &Path) -> Option<FormatId> {
match path.extension().and_then(OsStr::to_str) {
Some("cbz") => Some(FormatId::Cbz),
Some("pdf") => Some(FormatId::Pdf),
_ => None,
}
}
}
pub trait FormatReader: Send + Sync {
fn read(&self, input: &Path) -> Result<Document>;
}
pub trait FormatWriter: Send + Sync {
fn write(&self, doc: &Document, output: &Path) -> Result<()>;
}