danwi 0.4.2

Zero-cost dimensional analysis library with SI units, compile-time checking, and no_std support
Documentation
use super::{Unit, UnitDef};
use crate::quantity::Quantity;
use core::ops::Mul;

// `scalar * Unit<M>` constructs a `Quantity` stored in SI base units. The
// scale/offset is applied at construction so all downstream arithmetic is
// free of conversion overhead.

#[cfg(feature = "f32")]
impl<M: UnitDef> Mul<Unit<M>> for f32 {
    type Output = Quantity<f32, M::Dim>;

    #[inline(always)]
    fn mul(self, _unit: Unit<M>) -> Self::Output {
        Quantity::from_base(crate::scalar::to_base_f32(
            self,
            M::SCALE_NUM,
            M::SCALE_DEN,
            M::OFFSET_NUM,
            M::OFFSET_DEN,
        ))
    }
}

#[cfg(feature = "f64")]
impl<M: UnitDef> Mul<Unit<M>> for f64 {
    type Output = Quantity<f64, M::Dim>;

    #[inline(always)]
    fn mul(self, _unit: Unit<M>) -> Self::Output {
        Quantity::from_base(crate::scalar::to_base_f64(
            self,
            M::SCALE_NUM,
            M::SCALE_DEN,
            M::OFFSET_NUM,
            M::OFFSET_DEN,
        ))
    }
}