pub struct ValidatorRegistry { /* private fields */ }Expand description
Registry that maps FileType values to cached validator instances.
This is the extension point for the validation engine. A
ValidatorRegistry owns pre-constructed Validator instances for each
supported FileType, eliminating per-file instantiation overhead.
Most callers should use ValidatorRegistry::with_defaults to obtain a
registry pre-populated with all built-in validators. For advanced use cases
(custom providers, disabling validators), use ValidatorRegistry::builder.
Implementations§
Source§impl ValidatorRegistry
impl ValidatorRegistry
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a registry pre-populated with built-in validators.
Sourcepub fn builder() -> ValidatorRegistryBuilder
pub fn builder() -> ValidatorRegistryBuilder
Create a ValidatorRegistryBuilder for ergonomic construction.
§Example
use agnix_core::ValidatorRegistry;
let registry = ValidatorRegistry::builder()
.with_defaults()
.without_validator("XmlValidator")
.build();Sourcepub fn register(&mut self, file_type: FileType, factory: ValidatorFactory)
pub fn register(&mut self, file_type: FileType, factory: ValidatorFactory)
Register a validator factory for a given file type.
The factory is called exactly once at registration time. If the
validator’s name appears in the disabled set, the instance is
immediately dropped (the factory is still called once to obtain the
validator name). For built-in validators registered via
with_defaults(), this factory
call is avoided automatically using static names.
Sourcepub fn total_validator_count(&self) -> usize
pub fn total_validator_count(&self) -> usize
Return the total number of cached validator instances across all file types.
Sourcepub fn total_factory_count(&self) -> usize
👎Deprecated since 0.12.2: renamed to total_validator_count() - validators are now cached, not re-instantiated
pub fn total_factory_count(&self) -> usize
renamed to total_validator_count() - validators are now cached, not re-instantiated
Return the total number of registered validator instances across all file types.
Sourcepub fn validators_for(&self, file_type: FileType) -> &[Box<dyn Validator>]
pub fn validators_for(&self, file_type: FileType) -> &[Box<dyn Validator>]
Return a reference to the cached validator instances for the given file type.
Returns an empty slice if no validators are registered for file_type.
Instances whose name() appeared in the
disabled_validators set were already excluded at registration time.
Sourcepub fn disable_validator(&mut self, name: &'static str)
pub fn disable_validator(&mut self, name: &'static str)
Disable a validator by name at runtime.
The name must match the value returned by Validator::name()
(e.g., "XmlValidator"). Matching cached instances are removed from all
file types. This is an O(n) scan over all cached validators, which is
acceptable since this method is only called at startup.
Sourcepub fn disable_validator_owned(&mut self, name: &str)
pub fn disable_validator_owned(&mut self, name: &str)
Disable a validator by name from a runtime string.
Prefer disable_validator for
string literals.
Sourcepub fn disabled_validator_count(&self) -> usize
pub fn disabled_validator_count(&self) -> usize
Return the number of validator names currently disabled.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ValidatorRegistry
impl !RefUnwindSafe for ValidatorRegistry
impl Send for ValidatorRegistry
impl Sync for ValidatorRegistry
impl Unpin for ValidatorRegistry
impl UnsafeUnpin for ValidatorRegistry
impl !UnwindSafe for ValidatorRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more