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
| Attribute | Type | Description |
|---|---|---|
| strict | bool | Determines whether to enforce strict type validation or allow coercion during set membership checks. |
| item_validator | Arc< CombinedValidator > | The validator instance used to verify and process each individual element within the set. |
| min_length | Option< usize > = None | The minimum number of unique elements required for the set to be considered valid. |
| max_length | Option< usize > = None | The maximum number of unique elements allowed in the set before validation fails. |
| name | String | The identifying label for the validator used in error messages and schema representations. |
| fail_fast | bool | Indicates 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
| Name | Type | Description |
|---|---|---|
| strict | bool | Whether to enforce strict validation. |
| item_validator | Arc< CombinedValidator > | The validator used for individual items within the set. |
| min_length | Option< usize > | The minimum number of items required in the set. |
| max_length | Option< usize > | The maximum number of items allowed in the set. |
| name | String | The name identifier for the validator instance. |
| fail_fast | bool | Whether 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
| Name | Type | Description |
|---|---|---|
| input | Any | The 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
| Type | Description |
|---|---|
Set | A 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
| Type | Description |
|---|---|
String | The name of the validator, typically including the item type (e.g., 'set< int >') |