+17
-3
src/main.rs
+17
-3
src/main.rs
···
48
48
title: String,
49
49
artist: String,
50
50
album: Option<String>,
51
+
#[serde(skip_serializing_if = "Option::is_none")]
51
52
cover_bytes: Option<u64>,
53
+
#[serde(skip_serializing_if = "Vec::is_empty")]
54
+
validation_errors: Vec<String>,
52
55
}
53
56
54
57
impl AudioFileEntry {
55
-
fn to_summary(&self) -> AudioFileSummary {
58
+
fn to_summary_with_validators(&self, validators: Option<&[Box<dyn Validator>]>) -> AudioFileSummary {
56
59
let title = self.tags.title().unwrap_or("Unknown").to_string();
57
60
let artist = self.tags.artist().unwrap_or("Unknown").to_string();
58
61
···
64
67
None => (None, None),
65
68
};
66
69
70
+
// collect validation errors if validators provided
71
+
let mut errors = Vec::new();
72
+
if let Some(vals) = validators {
73
+
for v in vals.iter() {
74
+
if let Some(reason) = v.validate(self) {
75
+
errors.push(reason);
76
+
}
77
+
}
78
+
}
79
+
67
80
AudioFileSummary {
68
81
path: self.path.clone(),
69
82
title,
70
83
artist,
71
84
album,
72
85
cover_bytes: cover_size,
86
+
validation_errors: errors,
73
87
}
74
88
}
75
89
}
···
311
325
match args.output {
312
326
Output::Json => {
313
327
// pretty JSON array
314
-
let summaries: Vec<_> = audio_files.into_iter().map(|e| e.to_summary()).collect();
328
+
let summaries: Vec<_> = audio_files.into_iter().map(|e| e.to_summary_with_validators(Some(&validators))).collect();
315
329
match serde_json::to_string_pretty(&summaries) {
316
330
Ok(s) => println!("{}", s),
317
331
Err(e) => eprintln!("Failed to serialize summaries to pretty JSON: {}", e),
···
330
344
match args.output {
331
345
Output::Debug => println!("{:?}", entry),
332
346
Output::Json => {
333
-
let summary = entry.to_summary();
347
+
let summary = entry.to_summary_with_validators(Some(&validators));
334
348
match serde_json::to_string(&summary) {
335
349
Ok(s) => println!("{}", s),
336
350
Err(e) => eprintln!("Failed to serialize JSON for {}: {}", entry.path.display(), e),