pub trait Validator {
// Provided methods
fn is_valid_input(&self, _s: &mut String, _suppress_fill: bool) -> bool { ... }
fn is_valid(&self, _s: &str) -> bool { ... }
fn error(&self, _ctx: &mut Context<'_>) { ... }
fn validate(&self, s: &str, ctx: &mut Context<'_>) -> bool { ... }
fn is_status_ok(&self) -> bool { ... }
fn transfer_get(&self, _s: &str) -> Option<FieldValue> { ... }
fn transfer_set(&self, _v: &FieldValue) -> Option<String> { ... }
}Expand description
An input validator.
An InputLine holds an
Option<Box<dyn Validator>>; with no validator every input is accepted. The
default methods all accept; concrete validators override them.
§Turbo Vision heritage
Ports the abstract TValidator base class (tvalidator.cpp); the subclass
hierarchy becomes this trait (deviation D2).
Provided Methods§
Sourcefn is_valid_input(&self, _s: &mut String, _suppress_fill: bool) -> bool
fn is_valid_input(&self, _s: &mut String, _suppress_fill: bool) -> bool
Check (and optionally auto-fill/modify) s as it is being typed. May
mutate s in place (e.g. a picture validator inserting literal
characters). suppress_fill asks it not to auto-fill. Default: accept, no
change. Object-safe: &self, s: &mut String.
Sourcefn is_valid(&self, _s: &str) -> bool
fn is_valid(&self, _s: &str) -> bool
The final-form check, run when the field must be fully valid (the
modal-OK / focus-release path). Override this to enforce your validity
rule; the base accepts every string. Prefer validate
when you also need to pop the error box on failure.
Default: true.
Sourcefn error(&self, _ctx: &mut Context<'_>)
fn error(&self, _ctx: &mut Context<'_>)
Report an invalid final value. Concrete validators pop up a message box via
the async-modal-from-a-view seam (Context::request_message_box,
answer_to/then_command both None — informational, OK-only); the base
is a no-op.
Sourcefn validate(&self, s: &str, ctx: &mut Context<'_>) -> bool
fn validate(&self, s: &str, ctx: &mut Context<'_>) -> bool
Validate s and, if invalid, pop the error box. Call this at the
field-commit point (modal OK / focus release): it calls is_valid, and on
failure calls error to display the message box before returning false.
Returns true immediately when valid without touching the context.
A provided method; override is_valid and error rather than this.
Sourcefn is_status_ok(&self) -> bool
fn is_status_ok(&self) -> bool
Whether the validator’s status is OK — consulted when the field must
commit. The base never enters a non-OK status, so the default is true;
PXPictureValidator overrides to report a malformed mask.
Sourcefn transfer_get(&self, _s: &str) -> Option<FieldValue>
fn transfer_get(&self, _s: &str) -> Option<FieldValue>
Report the field’s current text s as a typed FieldValue during a
dialog gather walk. Return Some(typed value) when the validator has
transfer enabled and can parse the text; return None to leave the input
line carrying its plain text (the default, meaning “I don’t transfer”).
Override this together with transfer_set to
participate in dialog data transfer.
Sourcefn transfer_set(&self, _v: &FieldValue) -> Option<String>
fn transfer_set(&self, _v: &FieldValue) -> Option<String>
Format a typed FieldValue back to the field’s text during a dialog
scatter walk. Return Some(text) when transfer is enabled and v
is the type this validator handles; return None to leave the input line
on its own text path (the default).
Override this together with transfer_get to
participate in dialog data transfer.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl Validator for FilterValidator
impl Validator for LookupValidator
Accept-all: all default methods from the base Validator trait suffice.