unitforge 0.5.1

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

#[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 VelocitySquaredUnit {
    msq_ssq,
    J_kg,
    kJ_kg,
}

impl VelocitySquaredUnit {
    pub const fn base_per_x_const(self) -> (f64, i32) {
        match self {
            VelocitySquaredUnit::msq_ssq => (1., 0),
            VelocitySquaredUnit::J_kg => (1., 0),
            VelocitySquaredUnit::kJ_kg => (1., 3),
        }
    }
}

impl PhysicsUnit for VelocitySquaredUnit {
    fn name(&self) -> &str {
        match &self {
            VelocitySquaredUnit::msq_ssq => "m²/s²",
            VelocitySquaredUnit::J_kg => "J/kg",
            VelocitySquaredUnit::kJ_kg => "kJ/kg",
        }
    }

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

impl_quantity!(
    VelocitySquared,
    VelocitySquaredUnit,
    [VelocitySquaredUnit::J_kg]
);
impl_div_with_self_to_f64!(VelocitySquared);

impl_mul_with_self!(Velocity, VelocitySquared);