pub enum NumericUnit {
Mass(Decimal, MassUnit),
Length(Decimal, LengthUnit),
Volume(Decimal, VolumeUnit),
Duration(Decimal, DurationUnit),
Temperature(Decimal, TemperatureUnit),
Power(Decimal, PowerUnit),
Force(Decimal, ForceUnit),
Pressure(Decimal, PressureUnit),
Energy(Decimal, EnergyUnit),
Frequency(Decimal, FrequencyUnit),
Data(Decimal, DataUnit),
Money(Decimal, MoneyUnit),
}Expand description
A unified type for all numeric units (physical quantities and money)
This provides consistent behavior for all unit types:
- Comparisons always compare numeric values (ignoring units)
- Same-unit arithmetic preserves the unit
- Cross-unit arithmetic produces dimensionless numbers
Variants§
Mass(Decimal, MassUnit)
Length(Decimal, LengthUnit)
Volume(Decimal, VolumeUnit)
Duration(Decimal, DurationUnit)
Temperature(Decimal, TemperatureUnit)
Power(Decimal, PowerUnit)
Force(Decimal, ForceUnit)
Pressure(Decimal, PressureUnit)
Energy(Decimal, EnergyUnit)
Frequency(Decimal, FrequencyUnit)
Data(Decimal, DataUnit)
Money(Decimal, MoneyUnit)
Implementations§
Source§impl NumericUnit
impl NumericUnit
Sourcepub fn same_category(&self, other: &NumericUnit) -> bool
pub fn same_category(&self, other: &NumericUnit) -> bool
Check if two units are the same category
Sourcepub fn with_value(&self, new_value: Decimal) -> NumericUnit
pub fn with_value(&self, new_value: Decimal) -> NumericUnit
Create a new NumericUnit with the same unit type but different value This is the key method that eliminates type enumeration in operations
Sourcepub fn validate_same_currency(
&self,
other: &NumericUnit,
) -> Result<(), LemmaError>
pub fn validate_same_currency( &self, other: &NumericUnit, ) -> Result<(), LemmaError>
Validate that two Money units have the same currency Returns Ok for non-Money units or matching currencies
Trait Implementations§
Source§impl Clone for NumericUnit
impl Clone for NumericUnit
Source§fn clone(&self) -> NumericUnit
fn clone(&self) -> NumericUnit
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for NumericUnit
impl Debug for NumericUnit
Source§impl Display for NumericUnit
impl Display for NumericUnit
Source§impl PartialEq for NumericUnit
impl PartialEq for NumericUnit
Source§impl Serialize for NumericUnit
impl Serialize for NumericUnit
impl StructuralPartialEq for NumericUnit
Auto Trait Implementations§
impl Freeze for NumericUnit
impl RefUnwindSafe for NumericUnit
impl Send for NumericUnit
impl Sync for NumericUnit
impl Unpin for NumericUnit
impl UnwindSafe for NumericUnit
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more