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§
Sourcetype Numeric: Bounded + ToPrimitive + Zero + One
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§
Provided Methods§
Sourcefn is_nonzero() -> bool
fn is_nonzero() -> bool
Whether or not this numeric type disallows nonzero values.
Sourcefn requires_nonzero_exclusion() -> bool
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.
Sourcefn get_encoded_zero_value() -> Number
fn get_encoded_zero_value() -> Number
Gets the JSON encoded version of the zero value for the integral numeric type.
Sourcefn get_enforced_min_bound() -> f64
fn get_enforced_min_bound() -> f64
Gets the minimum bound for this numeric type, limited by the representable range in JSON Schema.
Sourcefn get_enforced_max_bound() -> f64
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.