data_doctor_core/
lib.rs

1//! # DataDoctor Core
2//!
3//! Core library for DataDoctor - a data validation and cleaning engine.
4//!
5//! This crate provides the fundamental data processing capabilities
6//! for detecting, diagnosing, and fixing data quality issues.
7
8pub mod csv;
9pub mod json;
10pub mod report;
11pub mod schema;
12
13pub use report::{ValidationIssue, ValidationResult};
14pub use schema::Schema;
15use std::io::Read;
16
17/// Main library entry point
18pub fn version() -> &'static str {
19    env!("CARGO_PKG_VERSION")
20}
21
22/// Options for configuring the validation process
23#[derive(Debug, Clone)]
24pub struct ValidationOptions {
25    /// Stop validation after this many errors (0 = unlimited)
26    pub max_errors: usize,
27    /// Schema to validate against
28    pub schema: Option<Schema>,
29    /// Whether to auto-fix simple issues where possible
30    pub auto_fix: bool,
31    /// Delimiter for CSV files
32    pub csv_delimiter: u8,
33}
34
35impl Default for ValidationOptions {
36    fn default() -> Self {
37        Self {
38            max_errors: 0,
39            schema: None,
40            auto_fix: false,
41            csv_delimiter: b',',
42        }
43    }
44}
45
46/// Trait for implementing data validators
47pub trait Validator {
48    /// Validates data based on the provided options
49    fn validate(&self, options: &ValidationOptions) -> ValidationResult;
50}
51
52/// Validates a JSON stream
53///
54/// # Arguments
55/// * `reader` - Input stream containing JSON data
56/// * `options` - Validation configuration options
57pub fn validate_json_stream<R: Read>(reader: R, options: &ValidationOptions) -> ValidationResult {
58    json::validate_json_stream(reader, options)
59}
60
61/// Validates a CSV stream
62///
63/// # Arguments
64/// * `reader` - Input stream containing CSV data
65/// * `options` - Validation configuration options
66pub fn validate_csv_stream<R: Read>(reader: R, options: &ValidationOptions) -> ValidationResult {
67    csv::validate_csv_stream(reader, options)
68}
69
70#[cfg(test)]
71mod tests {
72    use super::*;
73
74    #[test]
75    fn test_version() {
76        assert!(!version().is_empty());
77    }
78
79    #[test]
80    fn test_validation_options_default() {
81        let options = ValidationOptions::default();
82        assert_eq!(options.max_errors, 0);
83        assert!(!options.auto_fix);
84    }
85}