Expand description
Effect type aliases and helpers for debtmap analysis.
This module provides type aliases that integrate stillwater’s effect system with debtmap’s environment and error types. Using these aliases:
- Reduces boilerplate in function signatures
- Centralizes the environment and error types
- Makes it easy to refactor if types change
§Effect vs Validation
-
Effect: Represents a computation that may perform I/O and may fail. Use for operations like reading files or loading coverage data.
-
Validation: Represents a validation check that accumulates ALL errors instead of failing at the first one. Use for configuration validation, input checking, and anywhere you want comprehensive error reporting.
§Reader Pattern (Spec 199)
This module also provides Reader pattern helpers using stillwater 0.11.0’s
zero-cost ask, asks, and local primitives. The Reader pattern eliminates
config parameter threading by making configuration available through the
environment.
§Progress Effects (Spec 262)
The progress submodule provides combinators for composable progress reporting:
progress::with_stage: Wrap an effect with stage trackingprogress::traverse_with_progress: Sequential traversal with progressprogress::par_traverse_with_progress: Parallel traversal with atomic progressprogress::report_progress: Direct progress reporting effect
§Writer Effect for Telemetry (Spec 002)
The telemetry submodule provides the Writer Effect pattern for collecting
analysis telemetry without threading state through function parameters:
telemetry::AnalysisEvent: Events emitted during analysistelemetry::AnalysisMetrics: Collection of events with Monoid accumulationtelemetry::AnalysisSummary: Aggregated summary statisticstelemetry::tell_event: Emit a single telemetry eventtelemetry::tell_events: Emit multiple telemetry events
use debtmap::effects::telemetry::{tell_event, AnalysisEvent, AnalysisMetrics};
use stillwater::WriterEffectExt;
// Emit telemetry alongside computation
let effect = tell_event(AnalysisEvent::file_started(path.clone()))
.and_then(|_| do_analysis(path))
.tap_tell(|result| AnalysisMetrics::event(
AnalysisEvent::file_completed(path, result.duration_ms)
));
// Collect all events
let (result, metrics) = effect.run_writer(&env).await;
let summary: AnalysisSummary = metrics.into();§Sink Effect for Report Streaming (Spec 003)
The sink submodule provides the Sink Effect pattern for streaming analysis
reports with O(1) memory overhead:
sink::ReportLine: Report line types (JSON, text, header, separator)sink::emit_report_line: Emit a single report linesink::emit_json_line: Emit a JSON Lines formatted linesink::run_with_file_sink: Execute with file outputsink::run_with_stdout_sink: Execute with stdout output
use debtmap::effects::sink::{emit_header, emit_json_line, run_with_file_sink};
use stillwater::effect::sink::prelude::*;
// Stream results as they're generated
let effect = emit_header::<AnalysisError, ()>("Analysis Results")
.and_then(|_| emit_json_line(&file_metrics));
// Execute with file sink - constant memory
run_with_file_sink(effect, output_path, &()).await?;§Reader Pattern Benefits
Before (parameter threading):
fn analyze(ast: &Ast, config: &Config) -> Metrics {
calculate_complexity(ast, &config.thresholds)
}After (Reader pattern):
use debtmap::effects::asks_config;
fn analyze_effect<Env>(ast: Ast) -> impl Effect<...>
where Env: AnalysisEnv + Clone + Send + Sync
{
asks_config(move |config| calculate_complexity(&ast, &config.thresholds))
}§Available Reader Helpers
asks_config: Access the full config via closureasks_thresholds: Access thresholds config sectionasks_scoring: Access scoring weights config sectionasks_entropy: Access entropy config sectionlocal_with_config: Run effect with modified config (temporary override)
§Example: Using Effects
use debtmap::effects::AnalysisEffect;
use debtmap::env::AnalysisEnv;
use stillwater::Effect;
fn read_source(path: PathBuf) -> AnalysisEffect<String> {
Effect::from_fn(move |env: &dyn AnalysisEnv| {
env.file_system()
.read_to_string(&path)
.map_err(Into::into)
})
}§Example: Using Progress Effects
use debtmap::effects::progress::{with_stage, traverse_with_progress};
fn analyze_files(files: Vec<PathBuf>) -> AnalysisEffect<Vec<FileMetrics>> {
with_stage("Analysis", traverse_with_progress(
files,
"File Processing",
|path| analyze_file_effect(path)
))
}Re-exports§
pub use combinators::filter_effect;pub use combinators::filter_map_effect;pub use combinators::first;pub use combinators::fold_effect;pub use combinators::par_traverse_effect;pub use combinators::second;pub use combinators::sequence_effects;pub use combinators::traverse_effect;pub use combinators::zip_effect;pub use io::file_exists_effect;pub use io::is_dir_effect;pub use io::is_file_effect;pub use io::read_file_bytes_effect;pub use io::read_file_effect;pub use io::write_file_effect;
Modules§
- combinators
- Effect combinators for composing analysis operations.
- io
- File I/O effects for the analysis pipeline.
- progress
- Progress effects and combinators for composable progress reporting.
- sink
- Sink Effect for Report Streaming
- telemetry
- Writer Effect for Analysis Telemetry
- validation
- Expanded validation patterns using stillwater’s predicate combinators.
Structs§
- Shared
Fn - A wrapper type that makes a shared function callable via
Fntraits.
Functions§
- ask_env
- Query the entire environment.
- asks_
config - Query config through closure - the core Reader pattern primitive.
- asks_
entropy - Query entropy config section.
- asks_
scoring - Query scoring weights config section.
- asks_
thresholds - Query thresholds config section.
- combine_
validations - Combine multiple validations, accumulating all errors.
- effect_
fail - Create an effect from an error.
- effect_
from_ fn - Create an effect from a synchronous function.
- effect_
pure - Create an effect from a pure value (no I/O).
- get_
retry_ config - Get the effective retry config from a DebtmapConfig.
- is_
retry_ enabled - Check if retries are enabled in the given config.
- local_
with_ config - Run an effect with a temporarily modified config.
- run_
effect - Run an effect and convert the result to anyhow::Result for backwards compatibility.
- run_
effect_ async - Run an effect asynchronously.
- run_
effect_ with_ env - Run an effect with a custom environment.
- run_
validation - Convert a Validation result to anyhow::Result for backwards compatibility.
- validation_
failure - Create a failed validation result with a single error.
- validation_
failures - Create a failed validation result with multiple errors.
- validation_
map - Map a function over a validation’s success value.
- validation_
success - Create a successful validation result.
- with_
retry - Wrap an effect with retry logic using the configured policy.
- with_
retry_ from_ env - Wrap an effect with retry logic, using the retry config from environment.
Type Aliases§
- Analysis
Effect - Effect type for debtmap analysis operations.
- Analysis
Errors - Error collection type for validation accumulation.
- Analysis
Validation - Validation type for debtmap validations.