pub struct StringLookupValidator { /* private fields */ }Expand description
Valid iff the input exactly matches one entry in an owned list of strings.
On an invalid final value, error pops up an OK-only error message box.
Validation is a linear scan (O(n)) over the list, which preserves the
caller’s order (UI pickers may rely on it). StringLookupValidator::new_string_list replaces
the whole list.
§Turbo Vision heritage
Ports TStringLookupValidator (tvalidator.cpp). The lookup folds into
is_valid (deviation D2), the string collection becomes an owned
Vec<String>, and the streaming machinery is dropped (deviation D12).
C++ TStringLookupValidator held a sorted collection and binary-searched
(O(log n)). For the small fixed lists these validators carry, the linear
scan is simpler and fast enough; order preservation is the deliberate
trade-off.
Implementations§
Source§impl StringLookupValidator
impl StringLookupValidator
Sourcepub fn new(strings: Vec<String>) -> Self
pub fn new(strings: Vec<String>) -> Self
Build a validator that accepts only strings in strings. Pass an owned
Vec<String> of the allowed values; the order is preserved and used as
the iteration order for membership tests. Attach the result to an
InputLine to restrict the final value to
one of the listed entries.
Sourcepub fn new_string_list(&mut self, strings: Vec<String>)
pub fn new_string_list(&mut self, strings: Vec<String>)
Replace the accepted-string list at runtime, dropping the previous Vec.
Call this when the set of valid entries changes after the validator is
already in use — e.g. a dependent field whose allowed values depend on
another control’s selection. The new strings order becomes the
membership-test iteration order, exactly as in new; pass an
empty Vec to reject every input until the list is repopulated.
§Turbo Vision heritage
Ports TStringLookupValidator::newStringList. The C++ newStringList(nil)
form (dispose the list without installing a replacement) has no analog —
pass an empty Vec instead.
Trait Implementations§
Source§impl Validator for StringLookupValidator
impl Validator for StringLookupValidator
Source§fn error(&self, ctx: &mut Context<'_>)
fn error(&self, ctx: &mut Context<'_>)
Pop an OK-only “Input is not in list of valid strings” error box via
Context::request_message_box. Called automatically by
validate when
is_valid returns false.
Source§fn is_valid_input(&self, _s: &mut String, _suppress_fill: bool) -> bool
fn is_valid_input(&self, _s: &mut String, _suppress_fill: bool) -> bool
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.Source§fn validate(&self, s: &str, ctx: &mut Context<'_>) -> bool
fn validate(&self, s: &str, ctx: &mut Context<'_>) -> bool
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. Read moreSource§fn is_status_ok(&self) -> bool
fn is_status_ok(&self) -> bool
true;
PXPictureValidator overrides to report a malformed mask.Source§fn transfer_get(&self, _s: &str) -> Option<FieldValue>
fn transfer_get(&self, _s: &str) -> Option<FieldValue>
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”). Read moreSource§fn transfer_set(&self, _v: &FieldValue) -> Option<String>
fn transfer_set(&self, _v: &FieldValue) -> Option<String>
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). Read moreAuto Trait Implementations§
impl Freeze for StringLookupValidator
impl RefUnwindSafe for StringLookupValidator
impl Send for StringLookupValidator
impl Sync for StringLookupValidator
impl Unpin for StringLookupValidator
impl UnsafeUnpin for StringLookupValidator
impl UnwindSafe for StringLookupValidator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.