Skip to main content

dais_sidecar/
format.rs

1use std::path::Path;
2
3use crate::types::PresentationMetadata;
4
5/// Abstraction for sidecar file formats.
6///
7/// In v1, the only implementation is `.pdfpc`. Future formats (e.g., `.dais`)
8/// implement this same trait and slot in without changing downstream code.
9pub trait SidecarFormat {
10    /// Read metadata from a sidecar file.
11    fn read(&self, path: &Path) -> Result<PresentationMetadata, SidecarError>;
12
13    /// Write metadata to a sidecar file.
14    fn write(&self, path: &Path, metadata: &PresentationMetadata) -> Result<(), SidecarError>;
15
16    /// The file extension this format uses (e.g., "pdfpc").
17    fn file_extension(&self) -> &'static str;
18}
19
20/// Errors that can occur during sidecar operations.
21#[derive(Debug, thiserror::Error)]
22pub enum SidecarError {
23    /// Filesystem read/write failure.
24    #[error("I/O error: {0}")]
25    Io(#[from] std::io::Error),
26
27    /// The sidecar file could not be parsed.
28    #[error("Parse error at line {line}: {message}")]
29    Parse { line: usize, message: String },
30
31    /// A required sidecar section was absent.
32    #[error("Missing required section: {0}")]
33    MissingSection(String),
34}