Skip to main content

SetValidator

This class validates input data as a set, ensuring it meets specific length constraints and that each item conforms to a defined sub-validator. It supports both strict and flexible validation modes and can be configured to fail immediately upon the first validation error.

Attributes

AttributeTypeDescription
strictboolDetermines whether to enforce strict type validation or allow coercion during set membership checks.
item_validatorArc< CombinedValidator >The validator instance used to verify and process each individual element within the set.
min_lengthOption< usize > = NoneThe minimum number of unique elements required for the set to be considered valid.
max_lengthOption< usize > = NoneThe maximum number of unique elements allowed in the set before validation fails.
nameStringThe identifying label for the validator used in error messages and schema representations.
fail_fastboolIndicates whether validation should stop immediately upon encountering the first error within the set items.

Constructor

Signature

def SetValidator(
strict: bool,
item_validator: Arc< CombinedValidator >,
min_length: Option< usize >,
max_length: Option< usize >,
name: String,
fail_fast: bool
) - > [SetValidator](setvalidator.md?sid=validators_set_setvalidator)

Parameters

NameTypeDescription
strictboolWhether to enforce strict validation.
item_validatorArc< CombinedValidator >The validator used for individual items within the set.
min_lengthOption< usize >The minimum number of items required in the set.
max_lengthOption< usize >The maximum number of items allowed in the set.
nameStringThe name identifier for the validator instance.
fail_fastboolWhether to stop validation after the first error is encountered.

Methods


validate()

def validate(
input: Any,
state: [ValidationState](../validation/state/validationstate.md?sid=validators_validation_state_validationstate)
) - > Set

Validates that the input is a set-like collection and ensures each element conforms to the item validator's constraints.

Parameters

NameTypeDescription
inputAnyThe raw input data to be validated as a set collection
state[ValidationState](../validation/state/validationstate.md?sid=validators_validation_state_validationstate)The current validation context used for tracking errors and configuration

Returns

TypeDescription
SetA set containing the validated and potentially coerced items from the input collection

get_name()

def get_name() - > String

Returns the human-readable name of the validator used for error messages and schema identification.

Returns

TypeDescription
StringThe name of the validator, typically including the item type (e.g., 'set< int >')