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
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:
parent
48b560d85e
commit
034f0b142c
12 changed files with 468 additions and 150 deletions
49
src/formats/mod.rs
Normal file
49
src/formats/mod.rs
Normal 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<()>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue