pub struct RangeValidator { /* private fields */ }Expand description
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].
Whether the field also transfers its value as an FieldValue::Int is
off by default — enable it with set_transfer.
min/max are i32. On an out-of-range final value, error pops up an
OK-only message box naming the range.
§Turbo Vision heritage
Ports TRangeValidator (tvalidator.cpp), a filter subclass. The charset is
selected by the sign of min. Its final check adds a parse + range test on
top of the charset gate, while the while-typing check is the plain charset
filter (so a partial out-of-range number is accepted as input). Inheritance
becomes embed-and-delegate over a FilterValidator field (deviation D2);
the untyped value-transfer becomes the typed transfer_get/transfer_set
pair over FieldValue::Int (deviation D10); and the streaming machinery is
dropped (deviation D12).
Implementations§
Source§impl RangeValidator
impl RangeValidator
Sourcepub fn new(min: i32, max: i32) -> Self
pub fn new(min: i32, max: i32) -> Self
Build a range validator that requires the entered integer to be in
[min, max] (inclusive). The embedded charset filter is selected by
min: non-negative → digits + '+'; negative → digits + '+' +
'-'. Call set_transfer afterward
to enable typed i32 transfer for dialog gather/scatter; transfer is
off by default.
Sourcepub fn set_transfer(&mut self, enabled: bool)
pub fn set_transfer(&mut self, enabled: bool)
Enable/disable typed value transfer. Default OFF — until enabled,
transfer_get /
transfer_set return None and the input line
keeps its text value.
Trait Implementations§
Source§impl Validator for RangeValidator
impl Validator for RangeValidator
Source§fn is_valid(&self, s: &str) -> bool
fn is_valid(&self, s: &str) -> bool
Returns true iff s passes the charset gate, parses as an i32,
and falls within [min, max] (inclusive). All three conditions must
hold; the charset gate fires first so malformed input is caught early
without an attempted parse.
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
Charset-only while typing, no range check (delegated straight to the
embedded filter). So a partial, out-of-range number is accepted as input;
the range is enforced only at is_valid (the
final check).
Source§fn transfer_get(&self, s: &str) -> Option<FieldValue>
fn transfer_get(&self, s: &str) -> Option<FieldValue>
When transfer is enabled, report the field text as FieldValue::Int. A
failed parse falls back to Int(0); transfer only runs on already-valid
data, so that fallback is unreachable-but-safe.
Source§fn transfer_set(&self, v: &FieldValue) -> Option<String>
fn transfer_set(&self, v: &FieldValue) -> Option<String>
Format an Int back to text. None when transfer is disabled or v is
not an Int (the input line then takes its text path).
Source§fn error(&self, ctx: &mut Context<'_>)
fn error(&self, ctx: &mut Context<'_>)
Pop an OK-only error box naming the valid range (“Value not in the
range {min} to {max}”) 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.Auto Trait Implementations§
impl Freeze for RangeValidator
impl RefUnwindSafe for RangeValidator
impl Send for RangeValidator
impl Sync for RangeValidator
impl Unpin for RangeValidator
impl UnsafeUnpin for RangeValidator
impl UnwindSafe for RangeValidator
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.