Skip to main content

driven/sync/
propagator.rs

1//! Change propagation engine
2
3use super::SyncEngine;
4use crate::Result;
5use std::path::Path;
6
7/// Propagates changes to all enabled editors
8#[derive(Debug)]
9pub struct ChangePropagator<'a> {
10    sync_engine: &'a SyncEngine,
11}
12
13impl<'a> ChangePropagator<'a> {
14    /// Create a new propagator
15    pub fn new(sync_engine: &'a SyncEngine) -> Self {
16        Self { sync_engine }
17    }
18
19    /// Propagate changes from source to all targets
20    pub fn propagate(&self, project_root: &Path) -> Result<PropagationResult> {
21        let report = self.sync_engine.sync(project_root)?;
22
23        Ok(PropagationResult {
24            files_updated: report.synced_count(),
25            errors: report.errors.len(),
26        })
27    }
28}
29
30/// Result of change propagation
31#[derive(Debug)]
32pub struct PropagationResult {
33    /// Number of files updated
34    pub files_updated: usize,
35    /// Number of errors
36    pub errors: usize,
37}
38
39impl PropagationResult {
40    /// Check if propagation was successful
41    pub fn is_success(&self) -> bool {
42        self.errors == 0
43    }
44}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_propagation_result() {
52        let result = PropagationResult {
53            files_updated: 3,
54            errors: 0,
55        };
56        assert!(result.is_success());
57
58        let failed = PropagationResult {
59            files_updated: 1,
60            errors: 2,
61        };
62        assert!(!failed.is_success());
63    }
64}