Skip to main content

MeasureUnit

Struct MeasureUnit 

Source
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

Source

pub fn from_decimal_factor( name: String, decimal_factor: Decimal, derived_measure_factors: Vec<(String, i32)>, ) -> Result<Self, String>

Source

pub fn from_reference( name: String, written: String, segments: Vec<String>, reference_name: String, ) -> Self

Source

pub fn clear_constraint_magnitudes(&mut self)

Source

pub fn is_dynamic(&self) -> bool

Source

pub fn scale_written(&self) -> Option<String>

Source spelling of a reference scale (rate, or a product of targets).

Source

pub fn resolved_scale_factors(&self) -> &[(ReferenceTarget, i32)]

Declaring-spec scale factors after graph resolution. Empty when not dynamic.

Source

pub fn scale_reference_parts(&self) -> Option<(&[String], &str)>

Written reference path (segments + name) of an unresolved dynamic unit.

Source

pub fn literal_factor(&self) -> Option<&RationalInteger>

Literal conversion factor, when this unit’s scale is known at plan time.

Source

pub fn scale_coefficient(&self) -> RationalInteger

Plan-time coefficient for a dynamic scale (1 when literal or unresolved).

Source

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.

Source

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.

Source

pub fn is_canonical_factor(&self) -> bool

Source

pub fn is_positive_factor(&self) -> bool

Source

pub fn factor_decimal(&self) -> Decimal

Conversion factor as decimal (schema unit factors always commit).

Source

pub fn minimum_decimal(&self) -> Option<Decimal>

Source

pub fn maximum_decimal(&self) -> Option<Decimal>

Source

pub fn suggestion_magnitude_decimal(&self) -> Option<Decimal>

Source

pub fn maximum_canonical_decimal(&self) -> Option<Decimal>

Maximum bound lifted to canonical units via maximum * factor.

Source§

impl MeasureUnit

Source

pub fn with_decomposition(self, decomposition: BTreeMap<Dimension, i32>) -> Self

Source

pub fn with_factor(self, factor: RationalInteger) -> Self

Source

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.

Source

pub fn with_resolved_scale(self, resolved: ReferenceTarget) -> Self

Source

pub fn with_derived_measure_factors( self, derived_measure_factors: Vec<(String, i32)>, ) -> Self

Trait Implementations§

Source§

impl Clone for MeasureUnit

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MeasureUnit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for MeasureUnit

Source§

impl From<&MeasureUnit> for MeasureUnit

Source§

fn from(unit: &DomainMeasureUnit) -> Self

Converts to this type from the input type.
Source§

impl Hash for MeasureUnit

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for MeasureUnit

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MeasureUnit

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.