Trait ConfigurableNumber

Source
pub trait ConfigurableNumber {
    type Numeric: Bounded + ToPrimitive + Zero + One;

    // Required method
    fn class() -> NumberClass;

    // Provided methods
    fn is_nonzero() -> bool { ... }
    fn requires_nonzero_exclusion() -> bool { ... }
    fn get_encoded_zero_value() -> Number { ... }
    fn get_enforced_min_bound() -> f64 { ... }
    fn get_enforced_max_bound() -> f64 { ... }
}
Expand description

A numeric type that can be represented correctly in a JSON Schema document.

Required Associated Types§

Source

type Numeric: Bounded + ToPrimitive + Zero + One

The integral numeric type.

We parameterize the “integral” numeric type in this way to allow generating the schema for wrapper types such as NonZeroU64, where the overall type must be represented as NonZeroU64 but the integral numeric type that we’re constraining against is u64.

Required Methods§

Source

fn class() -> NumberClass

Gets the class of this numeric type.

Provided Methods§

Source

fn is_nonzero() -> bool

Whether or not this numeric type disallows nonzero values.

Source

fn requires_nonzero_exclusion() -> bool

Whether or not a generated schema for this numeric type must explicitly disallow zero values.

In some cases, such as NonZero* types from std::num, a numeric type may not support zero values for reasons of correctness and/or optimization. In some cases, we can simply adjust the normal minimum/maximum bounds in the schema to encode this. In other cases, such as signed versions like NonZeroI64, zero is a discrete value within the minimum and maximum bounds and must be excluded explicitly.

Source

fn get_encoded_zero_value() -> Number

Gets the JSON encoded version of the zero value for the integral numeric type.

Source

fn get_enforced_min_bound() -> f64

Gets the minimum bound for this numeric type, limited by the representable range in JSON Schema.

Source

fn get_enforced_max_bound() -> f64

Gets the maximum bound for this numeric type, limited by the representable range in JSON Schema.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ConfigurableNumber for f32

Source§

impl ConfigurableNumber for f64

Source§

impl ConfigurableNumber for i8

Source§

impl ConfigurableNumber for i16

Source§

impl ConfigurableNumber for i32

Source§

impl ConfigurableNumber for i64

Source§

impl ConfigurableNumber for isize

Source§

impl ConfigurableNumber for u8

Source§

impl ConfigurableNumber for u16

Source§

impl ConfigurableNumber for u32

Source§

impl ConfigurableNumber for u64

Source§

impl ConfigurableNumber for usize

Source§

impl ConfigurableNumber for NonZeroI8

Source§

impl ConfigurableNumber for NonZeroI16

Source§

impl ConfigurableNumber for NonZeroI32

Source§

impl ConfigurableNumber for NonZeroI64

Source§

impl ConfigurableNumber for NonZeroU8

Source§

impl ConfigurableNumber for NonZeroU16

Source§

impl ConfigurableNumber for NonZeroU32

Source§

impl ConfigurableNumber for NonZeroU64

Source§

impl ConfigurableNumber for NonZeroUsize

Implementors§