pub struct FilterValidator { /* private fields */ }Expand description
Accepts only characters drawn from an allowed set: every character of the
input must be a member of valid_chars. Empty input passes.
Membership is tested per Unicode char (valid_chars.contains(c)). On
an invalid final value, error pops up an OK-only error message box.
§Turbo Vision heritage
Ports TFilterValidator (tvalidator.cpp), which tests membership per byte
where tvision-rs tests per Unicode char (identical for the ASCII charsets these
validators carry). The streaming machinery is dropped (deviation D12).
Implementations§
Source§impl FilterValidator
impl FilterValidator
Sourcepub fn new(valid_chars: impl Into<String>) -> Self
pub fn new(valid_chars: impl Into<String>) -> Self
Build a filter that accepts only characters in valid_chars. Pass any
Into<String> — typically a string literal like "0123456789" or
"+-0123456789". Membership is tested per Unicode char.
Attach the result to an InputLine as
its validator to restrict what the user can type and what the final
value may contain.
Trait Implementations§
Source§impl Validator for FilterValidator
impl Validator for FilterValidator
Source§fn is_valid(&self, s: &str) -> bool
fn is_valid(&self, s: &str) -> bool
Returns true iff every char of s is in valid_chars. An empty
string passes (vacuously all characters are valid). Use this at the
final-commit check; for the while-typing path see is_valid_input.
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
Returns true iff every char of s is in valid_chars — the same
rule as is_valid, applied per-keystroke. Never mutates s (a filter
never auto-fills); suppress_fill is ignored.
Source§fn error(&self, ctx: &mut Context<'_>)
fn error(&self, ctx: &mut Context<'_>)
Pop an OK-only “Invalid character in input” error box via
Context::request_message_box. Called automatically by
validate when is_valid
returns false.
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 FilterValidator
impl RefUnwindSafe for FilterValidator
impl Send for FilterValidator
impl Sync for FilterValidator
impl Unpin for FilterValidator
impl UnsafeUnpin for FilterValidator
impl UnwindSafe for FilterValidator
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.