Skip to main content

Number

Struct Number 

Source
pub struct Number { /* private fields */ }
Expand description

(number feature) Accepts either an integer or a float, without converting between them.

Use this when a value may legitimately be whole or fractional and you want to keep its original type. Optional inclusive bounds and sign constraints compare the value numerically but never rewrite it.

Implementations§

Source§

impl Number

Source

pub fn with_meta(self, meta: Meta) -> Self

Attach human-facing metadata (name, description, examples, default, output conversion).

Source

pub fn new() -> Self

Source

pub fn min(self, min: f64) -> Self

Source

pub fn max(self, max: f64) -> Self

Source

pub fn range(self, start: f64, end: f64) -> Self

Source

pub fn positive(self) -> Self

Require the value to be strictly greater than zero.

Source

pub fn non_negative(self) -> Self

Require the value to be greater than or equal to zero.

Source

pub fn negative(self) -> Self

Require the value to be strictly less than zero.

Source

pub fn non_positive(self) -> Self

Require the value to be less than or equal to zero.

Trait Implementations§

Source§

impl Clone for Number

Source§

fn clone(&self) -> Number

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Number

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Number

Source§

fn default() -> Number

Returns the “default value” for a type. Read more
Source§

impl Validator for Number

Source§

fn meta(&self) -> &Meta

This validator’s human-facing metadata.
Source§

fn meta_mut(&mut self) -> &mut Meta

Mutable access to this validator’s metadata (backs the WithMeta builder setters).
Source§

fn check(&self, value: &mut Value) -> Result<(), Error>

The validation rule: check (and coerce) value in place.
Source§

fn validate(&self, value: &mut Value) -> Result<(), Error>

Run check; on error attach this validator’s Meta (innermost wins); on success apply the output conversion in meta().convert, if any.

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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithMeta for T
where T: Validator,

Source§

fn name(&self) -> &str

The human-readable name.
Source§

fn description(&self) -> Option<&str>

The description, if any.
Source§

fn examples(&self) -> &[(Value, Option<String>)]

The example values (each with an optional note).
Source§

fn default_value(&self) -> Option<&Value>

The default value, if any.
Source§

fn convert(&self) -> Option<ValueType>

The output conversion target, if any.
Source§

fn with_name(self, name: impl Into<String>) -> Self

Set the human-readable name (surfaced in error messages).
Source§

fn with_description(self, text: impl Into<String>) -> Self

Attach a human-readable description.
Source§

fn with_example(self, value: impl Into<Value>) -> Self

Add an example value.
Source§

fn with_example_noted( self, value: impl Into<Value>, note: impl Into<String>, ) -> Self

Add an example value with an explanatory note.
Source§

fn with_default(self, value: impl Into<Value>) -> Self

Set the default value used as an on-error fallback (see the pipeline’s validate stage).
Source§

fn to_string(self) -> Self

After validation succeeds, cast the value to a string.
Source§

fn to_int(self) -> Self

After validation succeeds, cast the value to an integer.
Source§

fn to_float(self) -> Self

After validation succeeds, cast the value to a float.
Source§

fn to_bool(self) -> Self

After validation succeeds, cast the value to a boolean.