Guide API
Skip to main content

RangeValidator

Struct RangeValidator 

Source
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

Source

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.

Source

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

Source§

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

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>

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>

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<'_>)

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

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. Read more
Source§

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.