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 StressRateUnit {
    Pa_s,
    kPa_s,
    MPa_s,
    GPa_s,
    bar_s,
    psi_s,
    bar_min,
}

impl StressRateUnit {
    pub const fn base_per_x_const(self) -> (f64, i32) {
        match self {
            StressRateUnit::Pa_s => (1., 0),
            StressRateUnit::kPa_s => (1., 3),
            StressRateUnit::MPa_s => (1., 6),
            StressRateUnit::GPa_s => (1., 9),
            StressRateUnit::bar_s => (1., 5),
            StressRateUnit::psi_s => (6.895, 3),
            StressRateUnit::bar_min => (1.0 / 60.0, 5),
        }
    }
}

impl PhysicsUnit for StressRateUnit {
    fn name(&self) -> &str {
        match &self {
            StressRateUnit::Pa_s => "Pa/s",
            StressRateUnit::kPa_s => "kPa/s",
            StressRateUnit::MPa_s => "MPa/s",
            StressRateUnit::GPa_s => "GPa/s",
            StressRateUnit::bar_s => "bar/s",
            StressRateUnit::psi_s => "psi/s",
            StressRateUnit::bar_min => "bar/min",
        }
    }

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

impl_quantity!(StressRate, StressRateUnit, [StressRateUnit::MPa_s]);
impl_div_with_self_to_f64!(StressRate);