Expand description
Input validators that gate what an InputLine
accepts.
Validator is a trait; an input line holds an
Option<Box<dyn Validator>> and, with no validator, accepts every input.
The crate ships several concrete validators: FilterValidator (an allowed
character set), RangeValidator (a numeric range),
LookupValidator / StringLookupValidator (membership in a set),
PXPictureValidator (a Paradox picture mask), and the Rust-native
RegexValidator.
§Object safety
Because the validator is stored as a boxed trait object, Validator is
object-safe: every method takes &self, no generics, no Self return.
validate is a provided method that dispatches through the overridable
is_valid/error.
§Typed value transfer
A validator can also convert between the field’s text and a typed
FieldValue — Validator::transfer_get reports the field’s value to a
dialog gather, and Validator::transfer_set formats a value back into the
field. Only validators with transfer enabled override these (for example
RangeValidator transfers an FieldValue::Int); the base returns
None, leaving the input line to use its plain text value.
Guide: Controls.
§Turbo Vision heritage
Ports TValidator and its subclasses (tvalidator.cpp). The abstract base
and its subclass hierarchy become this trait plus concrete impls (deviation
D2); the untyped value-transfer hook becomes the typed
transfer_get/transfer_set pair (deviation D10); and the streaming
machinery is dropped (deviation D12).
Structs§
- Filter
Validator - Accepts only characters drawn from an allowed set: every character of the
input must be a member of
valid_chars. Empty input passes. - Lookup
Validator - The accept-all base for lookup-style validators — it accepts every input.
- PXPicture
Validator - The Paradox picture-mask validator.
- Range
Validator - A numeric validator: it gates input through a digit charset filter (an
embedded
FilterValidator), then on the final check parses the text and requires it to fall within[min, max]. - Regex
Error - Error returned when compiling a
RegexValidatorpattern. - Regex
Validator - A
Validatordriven by a regular expression, giving the same two-phase behavior asPXPictureValidator—is_valid= the input fully matches the pattern;is_valid_input= the input is still a prefix of some complete match (“could it still become valid?”) — but expressed as a regex so callers can leverage regex knowledge instead of Paradox picture-mask syntax. - String
Lookup Validator - Valid iff the input exactly matches one entry in an owned list of strings.
On an invalid final value,
errorpops up an OK-only error message box.
Traits§
- Validator
- An input validator.