Struct Decrust

Source
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

Source

pub fn new() -> Self

Creates a new Decrust instance with default extractors and generators.

Source

pub fn register_parameter_extractor( &mut self, extractor: Box<dyn ParameterExtractor>, ) -> &mut Self

Registers a parameter extractor.

Source

pub fn register_fix_generator( &mut self, category: ErrorCategory, generator: Box<dyn FixGenerator>, ) -> &mut Self

Registers a fix generator for a specific error category.

Source

pub fn register_fix_template( &mut self, category: ErrorCategory, template: FixTemplate, ) -> &mut Self

Registers a fix template for a specific error category.

Source

pub fn extract_parameters(&self, error: &DecrustError) -> ExtractedParameters

Extracts parameters from an error using all registered extractors.

Source

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 the DecrustError 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.

Source

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);
    }
}
Source

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 output
  • check_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
Source

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);

Auto Trait Implementations§

§

impl Freeze for Decrust

§

impl !RefUnwindSafe for Decrust

§

impl !Send for Decrust

§

impl !Sync for Decrust

§

impl Unpin for Decrust

§

impl !UnwindSafe for Decrust

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more