1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//! Progress sink trait definitions for effects-based progress reporting.
//!
//! This module defines the core abstractions for progress reporting in debtmap:
//!
//! - [`ProgressSink`]: The main trait for progress receivers (TUI, CLI, silent, etc.)
//! - [`HasProgress`]: Environment extension trait for progress capability
//!
//! # Design Principles
//!
//! The progress system follows the "Pure Core, Imperative Shell" principle:
//!
//! - **Pure computation** functions don't call progress methods directly
//! - **Progress effects** are composed using combinators from [`crate::effects::progress`]
//! - **Progress sinks** handle the actual I/O (display, logging, etc.)
//!
//! # Thread Safety
//!
//! All `ProgressSink` implementations must be `Send + Sync` to support parallel
//! analysis with rayon. Progress updates may come from multiple threads concurrently.
//!
//! # Example
//!
//! ```rust,ignore
//! use debtmap::progress::traits::{ProgressSink, HasProgress};
//! use std::sync::Arc;
//!
//! // Custom progress sink
//! struct LoggingProgressSink;
//!
//! impl ProgressSink for LoggingProgressSink {
//! fn report(&self, stage: &str, current: usize, total: usize) {
//! log::info!("{}: {}/{}", stage, current, total);
//! }
//!
//! fn start_stage(&self, name: &str) {
//! log::info!("Starting: {}", name);
//! }
//!
//! fn complete_stage(&self, name: &str) {
//! log::info!("Complete: {}", name);
//! }
//!
//! fn warn(&self, message: &str) {
//! log::warn!("{}", message);
//! }
//!
//! fn child(&self, _prefix: &str) -> Arc<dyn ProgressSink> {
//! Arc::new(LoggingProgressSink)
//! }
//! }
//! ```
use Arc;
/// Progress sink abstraction - receives progress updates.
///
/// Implementations handle progress visualization (TUI, CLI, logging).
/// All methods should be cheap - expensive work should be deferred.
///
/// # Implementation Requirements
///
/// - All methods must be non-blocking
/// - Methods may be called from multiple threads concurrently
/// - Methods should not panic on invalid input (e.g., current > total)
/// - The `child` method should return a sink that prefixes stage names
///
/// # Method Costs
///
/// | Method | Expected Cost |
/// |--------|---------------|
/// | `report` | O(1), minimal allocation |
/// | `start_stage` | O(1), may log or update UI |
/// | `complete_stage` | O(1), may log or update UI |
/// | `warn` | O(1), may log |
/// | `child` | O(1), creates new Arc |
/// Environment extension for progress capability.
///
/// This trait extends the environment with progress reporting capability.
/// Environments implementing this trait can be used with progress combinators
/// like [`with_stage`](crate::effects::progress::with_stage) and
/// [`traverse_with_progress`](crate::effects::progress::traverse_with_progress).
///
/// # Example
///
/// ```rust,ignore
/// use debtmap::progress::traits::HasProgress;
/// use debtmap::env::RealEnv;
///
/// fn report_status<E: HasProgress>(env: &E) {
/// env.progress().start_stage("Analysis");
/// // ... do work ...
/// env.progress().complete_stage("Analysis");
/// }
/// ```