Skip to main content

NumericArgument

Trait NumericArgument 

Source
pub trait NumericArgument: Sealed + Sized {
    // Required methods
    fn require_zero(self, path: &str) -> ArgumentResult<Self>;
    fn require_non_zero(self, path: &str) -> ArgumentResult<Self>;
    fn require_positive(self, path: &str) -> ArgumentResult<Self>;
    fn require_non_negative(self, path: &str) -> ArgumentResult<Self>;
    fn require_negative(self, path: &str) -> ArgumentResult<Self>;
    fn require_non_positive(self, path: &str) -> ArgumentResult<Self>;
    fn require_less_than(self, path: &str, bound: Self) -> ArgumentResult<Self>;
    fn require_at_most(self, path: &str, bound: Self) -> ArgumentResult<Self>;
    fn require_greater_than(
        self,
        path: &str,
        bound: Self,
    ) -> ArgumentResult<Self>;
    fn require_at_least(self, path: &str, bound: Self) -> ArgumentResult<Self>;
    fn require_in_range<R>(self, path: &str, range: R) -> ArgumentResult<Self>
       where R: RangeBounds<Self>;
}
Expand description

Validates primitive numeric arguments while preserving their values.

Every successful method returns the original value without conversion or normalization. Failures contain structured comparison or range data, and every method rejects floating-point NaN values with ArgumentErrorKind::NotANumber.

The trait is sealed and implemented only for primitive numeric types.

Required Methods§

Source

fn require_zero(self, path: &str) -> ArgumentResult<Self>

Requires this value to equal zero.

Success returns the original value without cloning. A nonzero value returns ArgumentErrorKind::Comparison with an EqualTo(0) constraint at path; NaN returns ArgumentErrorKind::NotANumber.

Source

fn require_non_zero(self, path: &str) -> ArgumentResult<Self>

Requires this value not to equal zero.

Success returns the original value without cloning. Zero returns ArgumentErrorKind::Comparison with a NotEqualTo(0) constraint at path; NaN returns ArgumentErrorKind::NotANumber.

Source

fn require_positive(self, path: &str) -> ArgumentResult<Self>

Requires this value to be strictly greater than zero.

Success returns the original value without cloning. A value that is not positive returns ArgumentErrorKind::Comparison with a GreaterThan(0) constraint at path; NaN returns ArgumentErrorKind::NotANumber.

Source

fn require_non_negative(self, path: &str) -> ArgumentResult<Self>

Requires this value to be greater than or equal to zero.

Success returns the original value without cloning. A negative value returns ArgumentErrorKind::Comparison with an AtLeast(0) constraint at path; NaN returns ArgumentErrorKind::NotANumber.

Source

fn require_negative(self, path: &str) -> ArgumentResult<Self>

Requires this value to be strictly less than zero.

Success returns the original value without cloning. A value that is not negative returns ArgumentErrorKind::Comparison with a LessThan(0) constraint at path; NaN returns ArgumentErrorKind::NotANumber.

Source

fn require_non_positive(self, path: &str) -> ArgumentResult<Self>

Requires this value to be less than or equal to zero.

Success returns the original value without cloning. A positive value returns ArgumentErrorKind::Comparison with an AtMost(0) constraint at path; NaN returns ArgumentErrorKind::NotANumber.

Source

fn require_less_than(self, path: &str, bound: Self) -> ArgumentResult<Self>

Requires this value to be strictly less than bound.

Success returns the original value without cloning. An unsatisfied comparison returns ArgumentErrorKind::Comparison with a LessThan constraint at path; a NaN value or bound returns ArgumentErrorKind::NotANumber.

Source

fn require_at_most(self, path: &str, bound: Self) -> ArgumentResult<Self>

Requires this value to be less than or equal to bound.

Success returns the original value without cloning. An unsatisfied comparison returns ArgumentErrorKind::Comparison with an AtMost constraint at path; a NaN value or bound returns ArgumentErrorKind::NotANumber.

Source

fn require_greater_than(self, path: &str, bound: Self) -> ArgumentResult<Self>

Requires this value to be strictly greater than bound.

Success returns the original value without cloning. An unsatisfied comparison returns ArgumentErrorKind::Comparison with a GreaterThan constraint at path; a NaN value or bound returns ArgumentErrorKind::NotANumber.

Source

fn require_at_least(self, path: &str, bound: Self) -> ArgumentResult<Self>

Requires this value to be greater than or equal to bound.

Success returns the original value without cloning. An unsatisfied comparison returns ArgumentErrorKind::Comparison with an AtLeast constraint at path; a NaN value or bound returns ArgumentErrorKind::NotANumber.

Source

fn require_in_range<R>(self, path: &str, range: R) -> ArgumentResult<Self>
where R: RangeBounds<Self>,

Requires this value to lie within range.

Standard inclusive, exclusive, and unbounded RangeBounds are supported. The range structure is validated before this value: reversed endpoints and equal endpoints with either endpoint excluded return ArgumentErrorKind::InvalidRangeConstraint. NaN endpoints or values return ArgumentErrorKind::NotANumber. An otherwise out-of-range value returns ArgumentErrorKind::Range. The range’s start and end accessors are each called exactly once, and all checks use that owned endpoint snapshot. Successful validation returns the original value without cloning.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> NumericArgument for T
where T: NumericValue,