Skip to main content

FrozenSetValidator

This class validates input data as a frozen set, ensuring the collection meets specific length constraints and that each element conforms to a defined item validator. It supports both strict and lax validation modes and can be configured to fail fast upon encountering the first validation error.

Attributes

AttributeTypeDescription
strictboolDetermines whether to enforce strict validation rules that disallow type coercion for the frozenset items.
item_validatorArc< CombinedValidator >The validator instance used to process and validate each individual element within the frozenset.
min_lengthOption< usize >The minimum number of unique elements required for the frozenset to be considered valid.
max_lengthOption< usize >The maximum number of unique elements allowed in the frozenset before validation fails.
nameStringThe display name of the validator used in error messages and schema representations.
fail_fastboolIndicates whether the validator should stop processing and return an error immediately upon encountering the first validation failure.

Constructor

Signature

def FrozenSetValidator(
strict: bool,
item_validator: Arc< CombinedValidator >,
min_length: Option< usize >,
max_length: Option< usize >,
name: String,
fail_fast: bool
)

Parameters

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

Signature

def FrozenSetValidator(
strict: bool = false,
item_validator: [CombinedValidator](../mod/combinedvalidator.md?sid=validators_mod_combinedvalidator),
min_length: int = None,
max_length: int = None,
fail_fast: bool = false
)

Parameters

NameTypeDescription
strictbool = falseWhether to enforce strict type checking and avoid implicit conversions during validation.
item_validator[CombinedValidator](../mod/combinedvalidator.md?sid=validators_mod_combinedvalidator)The validator used to verify each individual element within the set.
min_lengthint = NoneThe minimum number of elements required in the frozenset.
max_lengthint = NoneThe maximum number of elements allowed in the frozenset.
fail_fastbool = falseIf true, validation stops immediately after the first item failure rather than collecting all errors.

Methods


validate()

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

Validates an input value against the frozenset constraints, ensuring all items match the item validator and the set size is within the specified length limits.

Parameters

NameTypeDescription
input_valueAnyThe raw input data to be validated and converted into a frozenset.
state[ValidationState](../validation/state/validationstate.md?sid=validators_validation_state_validationstate)The current validation state used to track errors and context across nested validators.

Returns

TypeDescription
frozensetA frozenset containing the validated items if all constraints are met.