unitforge 0.5.3

A library for unit and quantity consistent computations in Rust
Documentation
use crate::impl_macros::macros::*;

#[cfg_attr(feature = "strum", derive(EnumIter))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int, from_py_object))]
pub enum MolarMassUnit {
    kg_mol,
    g_mol,
    kg_kmol,
}

impl MolarMassUnit {
    pub const fn base_per_x_const(self) -> (f64, i32) {
        match self {
            MolarMassUnit::kg_mol => (1., 0),
            MolarMassUnit::g_mol => (1., -3),
            MolarMassUnit::kg_kmol => (1., -3),
        }
    }
}

impl PhysicsUnit for MolarMassUnit {
    fn name(&self) -> &str {
        match &self {
            MolarMassUnit::kg_mol => "kg/mol",
            MolarMassUnit::g_mol => "g/mol",
            MolarMassUnit::kg_kmol => "kg/kmol",
        }
    }

    fn base_per_x(&self) -> (f64, i32) {
        (*self).base_per_x_const()
    }
}

impl_quantity!(MolarMass, MolarMassUnit, [MolarMassUnit::g_mol]);
impl_div_with_self_to_f64!(MolarMass);