Skip to main content

ValidatorProvider

Trait ValidatorProvider 

Source
pub trait ValidatorProvider: Send + Sync {
    // Required method
    fn validators(&self) -> Vec<(FileType, ValidatorFactory)>;

    // Provided methods
    fn name(&self) -> &str { ... }
    fn named_validators(
        &self,
    ) -> Vec<(FileType, Option<&'static str>, ValidatorFactory)> { ... }
}
Expand description

A provider of validator factories.

Implement this trait to supply validators from an external source (e.g., a plugin or a secondary rule set). The built-in validators are packaged as a BuiltinProvider (internal to the crate).

§Example

use agnix_core::{FileType, ValidatorFactory, ValidatorProvider, ValidatorRegistry};

struct MyProvider;

impl ValidatorProvider for MyProvider {
    fn validators(&self) -> Vec<(FileType, ValidatorFactory)> {
        // Return custom validators here
        vec![]
    }
}

let registry = ValidatorRegistry::builder()
    .with_defaults()
    .with_provider(&MyProvider)
    .build();

Required Methods§

Source

fn validators(&self) -> Vec<(FileType, ValidatorFactory)>

Return the validator factories supplied by this provider.

Provided Methods§

Source

fn name(&self) -> &str

Human-readable name for this provider.

Defaults to the unqualified struct name (e.g., "BuiltinProvider").

Source

fn named_validators( &self, ) -> Vec<(FileType, Option<&'static str>, ValidatorFactory)>

Return validator factories with optional static names.

This is a performance optimization hook, not a rename mechanism. When a name is Some(name), the registry can skip calling factory() entirely for disabled validators, avoiding the heap allocation that would otherwise be needed just to read the validator’s name.

§Name invariant

Each Some(name) must equal the value returned by factory().name(). Violating this silently breaks the disabled-validator mechanism: register_named() checks the static name against the disabled set, so a mismatch causes the wrong validator to be excluded or allows a disabled validator to slip through undetected. In debug builds, a #[cfg(debug_assertions)] check inside register_named() catches this early with zero overhead in release builds.

§Default implementation

The default implementation delegates to validators() and maps each entry into a (FileType, None, factory) tuple, incurring an extra allocation compared to a direct override. Providers that know their validator names at compile time should override this method and return Some(name) for each entry to avoid the overhead.

Implementors§