Module plugin

Module plugin 

Source
Expand description

Plugin system for extending cargo-perf with custom rules.

This module provides the infrastructure for creating custom performance rules that can be integrated with cargo-perf.

§Creating a Custom Rule

To create a custom rule, implement the Rule trait:

use cargo_perf::rules::{Rule, Diagnostic, Severity};
use cargo_perf::engine::AnalysisContext;

pub struct MyCustomRule;

impl Rule for MyCustomRule {
    fn id(&self) -> &'static str { "my-custom-rule" }
    fn name(&self) -> &'static str { "My Custom Rule" }
    fn description(&self) -> &'static str { "Detects my custom anti-pattern" }
    fn default_severity(&self) -> Severity { Severity::Warning }

    fn check(&self, ctx: &AnalysisContext) -> Vec<Diagnostic> {
        // Your detection logic here
        Vec::new()
    }
}

§Creating a Custom Binary

To use custom rules, create a new binary that combines built-in and custom rules:

use cargo_perf::plugin::{PluginRegistry, run_with_plugins};

fn main() {
    let mut registry = PluginRegistry::new();

    // Add all built-in rules
    registry.add_builtin_rules();

    // Add your custom rules
    registry.add_rule(Box::new(MyCustomRule));
    registry.add_rule(Box::new(AnotherCustomRule));

    // Run with the combined rule set
    run_with_plugins(registry);
}

§Configuration

Custom rules can be configured in cargo-perf.toml just like built-in rules:

[rules]
my-custom-rule = "warn"
another-custom-rule = "deny"

Structs§

PluginRegistry
A registry for managing both built-in and custom rules.
PluginRegistryBuilder
Builder pattern for creating a plugin registry with a fluent API.

Functions§

analyze_with_plugins
Analyze a path using a custom plugin registry.