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
| Attribute | Type | Description |
|---|---|---|
| strict | bool | Determines whether to enforce strict validation rules that disallow type coercion for the frozenset items. |
| item_validator | Arc< CombinedValidator > | The validator instance used to process and validate each individual element within the frozenset. |
| min_length | Option< usize > | The minimum number of unique elements required for the frozenset to be considered valid. |
| max_length | Option< usize > | The maximum number of unique elements allowed in the frozenset before validation fails. |
| name | String | The display name of the validator used in error messages and schema representations. |
| fail_fast | bool | Indicates 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
| Name | Type | Description |
|---|---|---|
| strict | bool | Whether to validate the set in strict mode. |
| item_validator | Arc< CombinedValidator > | The validator used for individual items within the frozen set. |
| min_length | Option< usize > | The minimum number of items required in the frozen set. |
| max_length | Option< usize > | The maximum number of items allowed in the frozen set. |
| name | String | The name associated with the validator instance. |
| fail_fast | bool | Whether 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
| Name | Type | Description |
|---|---|---|
| strict | bool = false | Whether 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_length | int = None | The minimum number of elements required in the frozenset. |
| max_length | int = None | The maximum number of elements allowed in the frozenset. |
| fail_fast | bool = false | If 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
| Name | Type | Description |
|---|---|---|
| input_value | Any | The 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
| Type | Description |
|---|---|
frozenset | A frozenset containing the validated items if all constraints are met. |