Skip to main content

dpp_domain/domain/validation/
batch.rs

1//! Batch validation of multiple sector-data items in one pass.
2
3use super::functions::validate_sector_data;
4use crate::domain::field_error::ValidationErrors;
5use crate::domain::sector::SectorData;
6
7/// Result of validating a single item in a batch.
8#[derive(Debug, Clone)]
9pub struct BatchValidationItem {
10    /// Zero-based index in the input slice.
11    pub index: usize,
12    /// Validation result: `Ok(())` if valid, `Err` with field-level errors otherwise.
13    pub result: Result<(), ValidationErrors>,
14}
15
16/// Validate a batch of sector data items, collecting all errors per item.
17///
18/// The returned `Vec` has the same length and order as the input.
19pub fn validate_sector_data_batch(items: &[SectorData]) -> Vec<BatchValidationItem> {
20    items
21        .iter()
22        .enumerate()
23        .map(|(index, data)| BatchValidationItem {
24            index,
25            result: validate_sector_data(data),
26        })
27        .collect()
28}
29
30/// Returns only the failures from a batch validation run.
31pub fn batch_errors(results: &[BatchValidationItem]) -> Vec<&BatchValidationItem> {
32    results.iter().filter(|item| item.result.is_err()).collect()
33}