pub struct MeasureUnit {
pub name: String,
pub scale: UnitScale,
pub derived_measure_factors: Vec<(String, i32)>,
pub decomposition: BTreeMap<Dimension, i32>,
pub minimum: Option<RationalInteger>,
pub maximum: Option<RationalInteger>,
pub suggestion_magnitude: Option<RationalInteger>,
}Expand description
A single unit within a Measure type.
scale is the conversion factor: 1 of this unit equals scale canonical units
when the scale is a literal, or a referenced number when it is dynamic.
derived_measure_factors stores (measure_ref, exponent) pairs from compound unit declarations
(e.g., meter/second produces [("meter", 1), ("second", -1)]). Empty for base units.
decomposition is the dimensional decomposition vector, populated during the planning
decomposition pass. It is empty until that pass completes.
Fields§
§name: String§scale: UnitScale§derived_measure_factors: Vec<(String, i32)>§decomposition: BTreeMap<Dimension, i32>§minimum: Option<RationalInteger>Minimum magnitude in this unit (schema/UI); canonical bound is on the type.
maximum: Option<RationalInteger>Maximum magnitude in this unit (schema/UI).
suggestion_magnitude: Option<RationalInteger>Default suggestion magnitude in this unit (schema/UI).
Implementations§
Source§impl MeasureUnit
impl MeasureUnit
pub fn from_decimal_factor( name: String, decimal_factor: Decimal, derived_measure_factors: Vec<(String, i32)>, ) -> Result<Self, String>
pub fn from_reference( name: String, written: String, segments: Vec<String>, reference_name: String, ) -> Self
pub fn clear_constraint_magnitudes(&mut self)
pub fn is_dynamic(&self) -> bool
Sourcepub fn scale_written(&self) -> Option<String>
pub fn scale_written(&self) -> Option<String>
Source spelling of a reference scale (rate, or a product of targets).
Sourcepub fn resolved_scale_factors(&self) -> &[(ReferenceTarget, i32)]
pub fn resolved_scale_factors(&self) -> &[(ReferenceTarget, i32)]
Declaring-spec scale factors after graph resolution. Empty when not dynamic.
Sourcepub fn scale_reference_parts(&self) -> Option<(&[String], &str)>
pub fn scale_reference_parts(&self) -> Option<(&[String], &str)>
Written reference path (segments + name) of an unresolved dynamic unit.
Sourcepub fn literal_factor(&self) -> Option<&RationalInteger>
pub fn literal_factor(&self) -> Option<&RationalInteger>
Literal conversion factor, when this unit’s scale is known at plan time.
Sourcepub fn scale_coefficient(&self) -> RationalInteger
pub fn scale_coefficient(&self) -> RationalInteger
Plan-time coefficient for a dynamic scale (1 when literal or unresolved).
Sourcepub fn require_literal_factor(&self) -> &RationalInteger
pub fn require_literal_factor(&self) -> &RationalInteger
Literal conversion factor. Panics if this unit is reference-scaled: planning keeps every static path away from dynamic units.
Sourcepub fn same_scale(&self, other: &Self) -> bool
pub fn same_scale(&self, other: &Self) -> bool
Whether this unit and other have the same scale: equal literal factors, or
equal reference factor products with equal coefficient. Both types carry
the coordinates of the spec holding them (import hops are already prefixed on
the type), so target equality is coordinate equality.
pub fn is_canonical_factor(&self) -> bool
pub fn is_positive_factor(&self) -> bool
Sourcepub fn factor_decimal(&self) -> Decimal
pub fn factor_decimal(&self) -> Decimal
Conversion factor as decimal (schema unit factors always commit).
pub fn minimum_decimal(&self) -> Option<Decimal>
pub fn maximum_decimal(&self) -> Option<Decimal>
pub fn suggestion_magnitude_decimal(&self) -> Option<Decimal>
Sourcepub fn maximum_canonical_decimal(&self) -> Option<Decimal>
pub fn maximum_canonical_decimal(&self) -> Option<Decimal>
Maximum bound lifted to canonical units via maximum * factor.
Source§impl MeasureUnit
impl MeasureUnit
pub fn with_decomposition(self, decomposition: BTreeMap<Dimension, i32>) -> Self
pub fn with_factor(self, factor: RationalInteger) -> Self
Sourcepub fn with_reference_scale(
self,
factors: Vec<(ReferenceTarget, i32)>,
coefficient: RationalInteger,
) -> Self
pub fn with_reference_scale( self, factors: Vec<(ReferenceTarget, i32)>, coefficient: RationalInteger, ) -> Self
Replace this unit’s scale with a dynamic product of settled references and a plan-time coefficient from compound resolution.
pub fn with_resolved_scale(self, resolved: ReferenceTarget) -> Self
pub fn with_derived_measure_factors( self, derived_measure_factors: Vec<(String, i32)>, ) -> Self
Trait Implementations§
Source§impl Clone for MeasureUnit
impl Clone for MeasureUnit
Source§impl Debug for MeasureUnit
impl Debug for MeasureUnit
impl Eq for MeasureUnit
Source§impl From<&MeasureUnit> for MeasureUnit
impl From<&MeasureUnit> for MeasureUnit
Source§fn from(unit: &DomainMeasureUnit) -> Self
fn from(unit: &DomainMeasureUnit) -> Self
Source§impl Hash for MeasureUnit
impl Hash for MeasureUnit
Source§impl PartialEq for MeasureUnit
impl PartialEq for MeasureUnit
impl StructuralPartialEq for MeasureUnit
Auto Trait Implementations§
impl Forget for MeasureUnit
impl Freeze for MeasureUnit
impl Move for MeasureUnit
impl RefUnwindSafe for MeasureUnit
impl Send for MeasureUnit
impl Sync for MeasureUnit
impl Unpin for MeasureUnit
impl UnsafeUnpin for MeasureUnit
impl UnwindSafe for MeasureUnit
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.