Skip to main content

dictx_parser/
traits.rs

1use dictx_core::{DictEntry, Result};
2use std::path::Path;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct ValidationReport {
6    pub valid: bool,
7    pub format: String,
8    pub estimated_entries: Option<usize>,
9    pub issues: Vec<String>,
10}
11
12impl ValidationReport {
13    pub fn ok(format: impl Into<String>, estimated_entries: Option<usize>) -> Self {
14        Self {
15            valid: true,
16            format: format.into(),
17            estimated_entries,
18            issues: Vec::new(),
19        }
20    }
21
22    pub fn invalid(format: impl Into<String>, issue: impl Into<String>) -> Self {
23        Self {
24            valid: false,
25            format: format.into(),
26            estimated_entries: None,
27            issues: vec![issue.into()],
28        }
29    }
30}
31
32pub trait DictParser: Send + Sync {
33    fn name(&self) -> &'static str;
34    fn format_id(&self) -> &'static str;
35    fn validate(&self, path: &Path) -> Result<ValidationReport>;
36    fn parse(&self, path: &Path) -> Result<Box<dyn Iterator<Item = Result<DictEntry>>>>;
37}