pub enum UnitScale {
Literal(RationalInteger),
Unresolved {
written: String,
segments: Vec<String>,
name: String,
},
Reference {
factors: Vec<(ReferenceTarget, i32)>,
coefficient: RationalInteger,
},
}Expand description
Conversion factor of a measure unit: a plan-time rational, or a product of data/rule references whose values are known only during evaluation.
Dynamic scales carry a plan-time coefficient and one or more
(reference, exponent) factors:
effective = coefficient * Π settled(t_i)^e_i.
Plain -> unit gbp: rate uses coefficient 1 and factors [(rate, 1)].
-> unit gbp_per_kg: gbp/kilogram uses the gbp reference with
coefficient 1/kilogram and factors [(rate, 1)].
-> unit usd_per_ce: usd/consumenteneenheid uses two factors with
exponents 1 and -1.
Variants§
Literal(RationalInteger)
1 of this unit equals this many canonical units.
Unresolved
Written path between parse and classification (rate, fx.rate). The
declaring spec’s type resolution replaces it with Self::Reference or a
compound literal factor; it never survives type resolution.
Reference
Resolved number data fields or rules, in the coordinates of the spec whose
type resolution wrote them: local members, or uses hops plus members of
the imported spec. factors is non-empty after planning. After planning
succeeds every dynamic unit is this variant — never Self::Unresolved.
Implementations§
Source§impl UnitScale
impl UnitScale
pub fn dynamic_coefficient(&self) -> Option<&RationalInteger>
Sourcepub fn canonicalize_scale_factors(
factors: &[(ReferenceTarget, i32)],
) -> Vec<(ReferenceTarget, i32)>
pub fn canonicalize_scale_factors( factors: &[(ReferenceTarget, i32)], ) -> Vec<(ReferenceTarget, i32)>
Merge (target, exponent) pairs: same target adds exponents; drop zeros;
order by [ReferenceTarget] ord. Empty result means the product cancelled.
Trait Implementations§
impl Eq for UnitScale
impl StructuralPartialEq for UnitScale
Auto Trait Implementations§
impl Forget for UnitScale
impl Freeze for UnitScale
impl Move for UnitScale
impl RefUnwindSafe for UnitScale
impl Send for UnitScale
impl Sync for UnitScale
impl Unpin for UnitScale
impl UnsafeUnpin for UnitScale
impl UnwindSafe for UnitScale
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.