pub struct Decrust { /* private fields */ }
Expand description
Main struct for the Decrust autocorrection capabilities.
The Decrust
engine analyzes DecrustError
instances to provide
potential automated fixes or actionable suggestions for developers.
NEW: Now includes compile-time dependency analysis capabilities
that integrate with the decrust!
macro to provide real-time
dependency optimization and compatibility checking.
Implementations§
Source§impl Decrust
impl Decrust
Sourcepub fn register_parameter_extractor(
&mut self,
extractor: Box<dyn ParameterExtractor>,
) -> &mut Self
pub fn register_parameter_extractor( &mut self, extractor: Box<dyn ParameterExtractor>, ) -> &mut Self
Registers a parameter extractor.
Sourcepub fn register_fix_generator(
&mut self,
category: ErrorCategory,
generator: Box<dyn FixGenerator>,
) -> &mut Self
pub fn register_fix_generator( &mut self, category: ErrorCategory, generator: Box<dyn FixGenerator>, ) -> &mut Self
Registers a fix generator for a specific error category.
Sourcepub fn register_fix_template(
&mut self,
category: ErrorCategory,
template: FixTemplate,
) -> &mut Self
pub fn register_fix_template( &mut self, category: ErrorCategory, template: FixTemplate, ) -> &mut Self
Registers a fix template for a specific error category.
Sourcepub fn extract_parameters(&self, error: &DecrustError) -> ExtractedParameters
pub fn extract_parameters(&self, error: &DecrustError) -> ExtractedParameters
Extracts parameters from an error using all registered extractors.
Sourcepub fn suggest_autocorrection(
&self,
error: &DecrustError,
source_code_context: Option<&str>,
) -> Option<Autocorrection>
pub fn suggest_autocorrection( &self, error: &DecrustError, source_code_context: Option<&str>, ) -> Option<Autocorrection>
Suggests a potential autocorrection for a given DecrustError
.
This function first checks if the error contains embedded diagnostic information with pre-suggested fixes (e.g., from a compiler or linter). If not, it tries to use registered fix generators and templates based on extracted parameters. As a last resort, it falls back to the original category-based suggestions.
§Arguments
error
: A reference to theDecrustError
for which to suggest a fix.source_code_context
: Optional context of the source code where the error occurred. This can be used for more advanced context-aware suggestions.
§Returns
An Option<Autocorrection>
containing a suggested fix, or None
if no specific
automated suggestion is available for this particular error instance.
Sourcepub fn analyze_dependencies(
&mut self,
code: &str,
) -> Vec<DependencyAnalysisResult>
pub fn analyze_dependencies( &mut self, code: &str, ) -> Vec<DependencyAnalysisResult>
NEW: Analyzes dependencies used in the given code block
This method integrates with the decrust!
macro to provide real-time
dependency analysis, showing which crates are used, which features
are enabled vs. actually used, and version compatibility information.
§Arguments
code
- The source code to analyze for dependency usage
§Returns
A vector of DependencyAnalysisResult
containing detailed analysis
for each dependency found in the code.
§Example
use decrust_core::Decrust;
let mut decrust = Decrust::new();
let code = r#"
use serde::{Serialize, Deserialize};
use tokio::fs;
#[derive(Serialize, Deserialize)]
struct MyData {
value: String,
}
"#;
let analysis = decrust.analyze_dependencies(code);
for result in analysis {
println!("Crate: {}", result.crate_name);
println!("Used features: {:?}", result.used_features);
println!("Unused features: {:?}", result.unused_features);
for suggestion in &result.suggestions {
println!("Suggestion: {}", suggestion);
}
}
Sourcepub fn configure_dependency_analyzer(
&mut self,
verbose: bool,
check_latest: bool,
)
pub fn configure_dependency_analyzer( &mut self, verbose: bool, check_latest: bool, )
NEW: Configures the dependency analyzer settings
Allows customization of the dependency analysis behavior, such as enabling verbose output or network-based version checking.
§Arguments
verbose
- Whether to enable verbose analysis outputcheck_latest
- Whether to check for latest versions (requires network)
§Example
use decrust_core::Decrust;
let mut decrust = Decrust::new();
decrust.configure_dependency_analyzer(true, false); // Verbose but no network checks
Sourcepub fn generate_dependency_report(&mut self, code: &str) -> String
pub fn generate_dependency_report(&mut self, code: &str) -> String
NEW: Generates a dependency optimization report
Creates a comprehensive report showing all dependency analysis results with optimization suggestions and potential issues.
§Arguments
code
- The source code to analyze
§Returns
A formatted string containing the complete dependency analysis report
§Example
use decrust_core::Decrust;
let mut decrust = Decrust::new();
let code = "use serde::Serialize;";
let report = decrust.generate_dependency_report(code);
println!("{}", report);