organize_rs_core/
state.rs

1// TODO: Implement typestate for running organize
2// https://cliffle.com/blog/rust-typestate/
3
4use jwalk::DirEntry;
5
6use crate::{
7    actions::conflicts::ConflictResolutionKind, actors::location_walker::DirEntryData, rules::Rule,
8};
9
10// States
11#[derive(Debug, Clone, Copy, Default)]
12pub struct Initialize;
13
14#[derive(Debug, Clone, Copy, Default)]
15pub struct Filtering;
16
17#[derive(Debug, Default)]
18pub struct Inspection {
19    entries: Vec<(Rule, DirEntryData)>,
20}
21
22#[derive(Debug, Default)]
23pub struct ConflictHandling {
24    entries: Vec<(Rule, DirEntryData)>,
25    conflicts: Vec<DirEntry<((), ())>>,
26}
27
28impl Inspection {
29    pub fn with_entries(entries: Vec<(Rule, DirEntryData)>) -> Self {
30        Self { entries }
31    }
32
33    pub fn print_entries(&self) {
34        self.entries.iter().for_each(|(rule, entries)| {
35            entries.print_entries();
36            println!("Rule: {rule}");
37        })
38    }
39
40    pub fn entries(self) -> Vec<(Rule, DirEntryData)> {
41        self.entries
42    }
43}
44
45impl ConflictHandling {
46    pub fn with_entries(entries: Vec<(Rule, DirEntryData)>) -> Self {
47        Self {
48            entries,
49            conflicts: vec![],
50        }
51    }
52}
53
54#[derive(Debug, Default)]
55pub struct AskConfirmation;
56
57#[derive(Debug, Default)]
58pub struct ActionPreview {
59    entries: Vec<(Rule, DirEntryData)>,
60    conflicts: Option<Vec<ConflictResolutionKind>>,
61}
62
63impl ActionPreview {
64    pub fn with_entries(entries: Vec<(Rule, DirEntryData)>) -> Self {
65        Self {
66            entries,
67            conflicts: None,
68        }
69    }
70    pub fn entries(self) -> Vec<(Rule, DirEntryData)> {
71        self.entries
72    }
73}
74
75#[derive(Debug, Default)]
76pub struct ActionApplication {
77    entries: Vec<(Rule, DirEntryData)>,
78    conflicts: Option<Vec<ConflictResolutionKind>>,
79}
80
81impl ActionApplication {
82    pub fn with_entries(entries: Vec<(Rule, DirEntryData)>) -> Self {
83        Self {
84            entries,
85            conflicts: None,
86        }
87    }
88    pub fn entries(self) -> Vec<(Rule, DirEntryData)> {
89        self.entries
90    }
91}
92
93#[derive(Debug, Clone, Default)]
94pub struct Reporting;
95
96pub trait ProcessingStage {}
97
98impl ProcessingStage for Initialize {}
99impl ProcessingStage for Filtering {}
100impl ProcessingStage for Inspection {}
101impl ProcessingStage for ActionPreview {}
102impl ProcessingStage for AskConfirmation {}
103impl ProcessingStage for ActionApplication {}
104impl ProcessingStage for ConflictHandling {}
105impl ProcessingStage for Reporting {}