unitforge/quantities/
voltage.rs

1use crate::impl_macros::macros::*;
2use crate::prelude::*;
3use crate::quantities::*;
4use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
5use num_traits::identities::Zero;
6use num_traits::FromPrimitive;
7#[cfg(feature = "pyo3")]
8use pyo3::pyclass;
9#[cfg(feature = "serde")]
10use serde::{Deserialize, Serialize};
11use std::cmp::Ordering;
12use std::fmt;
13use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
14
15#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
16#[derive(Copy, Clone, PartialEq, Debug)]
17#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
18pub enum VoltageUnit {
19    V,
20    kV,
21    MV,
22    GV,
23    TV,
24}
25
26impl PhysicsUnit for VoltageUnit {
27    fn name(&self) -> &str {
28        match &self {
29            VoltageUnit::V => "V",
30            VoltageUnit::kV => "kV",
31            VoltageUnit::MV => "MV",
32            VoltageUnit::GV => "GV",
33            VoltageUnit::TV => "TV",
34        }
35    }
36
37    fn base_per_x(&self) -> (f64, i32) {
38        match self {
39            VoltageUnit::V => (1., 0),
40            VoltageUnit::kV => (1., 3),
41            VoltageUnit::MV => (1., 6),
42            VoltageUnit::GV => (1., 9),
43            VoltageUnit::TV => (1., 12),
44        }
45    }
46}
47
48impl_quantity!(Voltage, VoltageUnit, VoltageUnit::V);
49impl_div_with_self_to_f64!(Voltage);
50
51impl_mul!(Voltage, Charge, ForceDistance);