pub enum UnitScale {
Literal(RationalInteger),
Compound {
prefix: RationalInteger,
},
Unresolved {
written: String,
segments: Vec<String>,
name: String,
},
Reference {
factors: Vec<(ScaleTarget, 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_pack: usd/pack uses two factors with
exponents 1 and -1.
Variants§
Literal(RationalInteger)
1 of this unit equals this many canonical units.
Compound
A compound unit whose derived_measure_factors are not resolved yet. It has
no factor: prefix is only the written multiplier (3.6 in
3.6 meter/second). Type resolution replaces it with Self::Literal or
Self::Reference; it never survives type resolution.
Fields
prefix: RationalIntegerUnresolved
Written path between parse and classification (rate, fx.rate). The
declaring spec’s type resolution replaces it with Self::Reference or
Self::Compound; 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: &[(ScaleTarget, i32)],
) -> Vec<(ScaleTarget, i32)>
pub fn canonicalize_scale_factors( factors: &[(ScaleTarget, i32)], ) -> Vec<(ScaleTarget, 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 UnitScalewhere
*const u8 is !null: Freeze,
PhantomData<u32>: Freeze,
PhantomData<u8>: Freeze,
PhantomData<String>: Freeze,
PhantomData<(ScaleTarget, i32)>: Freeze,
impl Move for UnitScale
impl RefUnwindSafe for UnitScale
impl Send for UnitScale
impl Sync for UnitScale
impl Unpin for UnitScale
impl UnsafeUnpin for UnitScalewhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u32>: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
PhantomData<(ScaleTarget, i32)>: UnsafeUnpin,
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.