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, fx.rate).
Sourcepub fn resolved_scale_target(&self) -> Option<&ReferenceTarget>
pub fn resolved_scale_target(&self) -> Option<&ReferenceTarget>
Declaring-spec target after graph resolution.
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 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_consumer_scale(
&self,
other: &Self,
self_import_path: &[String],
other_import_path: &[String],
) -> bool
pub fn same_consumer_scale( &self, other: &Self, self_import_path: &[String], other_import_path: &[String], ) -> bool
Whether this unit and other have the same scale in consumer coordinates:
equal literal factors, or equal reference paths after prefixing each
owner’s import path.
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
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 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.