pub struct NumericRestrictions {
pub min: Option<NumericBound>,
pub max: Option<NumericBound>,
pub unit: Option<String>,
}Expand description
Inline numeric refinement carried by the numeric SchemaType variants.
None on the variant means “unconstrained” — the common, hot-path case, a
single tag rather than three carried inner Options. The empty restriction
set is never stored as Some: smart constructors and decoders collapse it to
None via NumericRestrictions::normalize, and well-formedness rejects a
stored Some(empty).
Fields§
§min: Option<NumericBound>§max: Option<NumericBound>§unit: Option<String>Free-form unit annotation. Schema/help metadata only: numeric
SchemaValues carry no unit, so value validation never checks it;
equivalence/subtyping require the normalized unit to match exactly.
Implementations§
Source§impl NumericRestrictions
impl NumericRestrictions
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
True when there is nothing to constrain (no bounds and no non-empty unit).
Sourcepub fn normalize(self) -> Option<NumericRestrictions>
pub fn normalize(self) -> Option<NumericRestrictions>
Collapse the empty restriction set to None, dropping an empty unit
and canonicalizing float bounds (so a decoded -0.0 becomes +0.0).
This enforces the canonicalization invariants that Some(empty) is never
constructed and that two restriction sets which differ only by float zero
sign compare equal (SchemaType derives Eq and feeds byte-equivalence).
Sourcepub fn validate_for_repr(
&self,
repr: NumericRepr,
) -> Result<(), NumericRestrictionError>
pub fn validate_for_repr( &self, repr: NumericRepr, ) -> Result<(), NumericRestrictionError>
Repr-aware well-formedness check, shared by every validation entry point (well-formedness, subtyping, value validation, macro refinement) so no path assumes a prior well-formedness pass.
Rejects: a stored empty set (Some(empty) must never exist), a bound
whose family does not match the repr, an integer repr carrying a float
bound, a bound that does not fit the repr’s range, an F32 bound that
does not round-trip through f32, and min > max (compared numerically).
Trait Implementations§
Source§impl Clone for NumericRestrictions
impl Clone for NumericRestrictions
Source§fn clone(&self) -> NumericRestrictions
fn clone(&self) -> NumericRestrictions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more