Skip to main content

ValidatorCollection

Trait ValidatorCollection 

pub trait ValidatorCollection<V> {
    // Required methods
    fn add_validator(self, validator: V) -> Self;
    fn sort_by_priority(self) -> Self;
}
Expand description

Helper trait for creating validator collections with type erasure.

This trait provides utilities for building collections of validators with automatic priority-based sorting and type erasure through Box wrappers.

§Usage Examples

use dotscope::metadata::validation::{ValidatorCollection, RawValidator, RawValidationContext};
use dotscope::Result;

struct TestValidator;
impl RawValidator for TestValidator {
    fn validate_raw(&self, _context: &RawValidationContext) -> Result<()> { Ok(()) }
    fn name(&self) -> &'static str { "TestValidator" }
}

let mut validators: Vec<Box<dyn RawValidator>> = Vec::new();
let validators = validators
    .add_validator(Box::new(TestValidator))
    .sort_by_priority();

Required Methods§

fn add_validator(self, validator: V) -> Self

Adds a validator to the collection.

§Arguments
  • validator - The validator to add to the collection
§Returns

Returns the updated collection with the validator added.

fn sort_by_priority(self) -> Self

Sorts validators by priority (highest first).

Validators with higher priority values are placed first in the collection, ensuring they execute before lower-priority validators.

§Returns

Returns the collection sorted by validator priority in descending order.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

§

impl ValidatorCollection<Box<dyn OwnedValidator>> for Vec<Box<dyn OwnedValidator>>

§

fn add_validator(self, validator: Box<dyn OwnedValidator>) -> Self

§

fn sort_by_priority(self) -> Self

§

impl ValidatorCollection<Box<dyn RawValidator>> for Vec<Box<dyn RawValidator>>

§

fn add_validator(self, validator: Box<dyn RawValidator>) -> Self

§

fn sort_by_priority(self) -> Self

Implementors§