pub use uom::si::f64::{
Capacitance, ElectricCharge, ElectricCurrent, ElectricPotential, ElectricalResistance,
Energy, Length, Power, Ratio, ThermodynamicTemperature, Time,
};
pub use uom::fmt::DisplayStyle;
pub use uom::si::Unit;
pub use uom::si::{
capacitance, electric_current, electric_potential, electrical_resistance, ratio,
thermodynamic_temperature,
};
pub mod electric_charge;
pub mod energy;
pub mod length;
pub mod power;
pub mod time;
#[inline]
pub fn meter(v: f64) -> Length {
Length::new::<length::meter>(v)
}
#[inline]
pub fn second(v: f64) -> Time {
Time::new::<time::second>(v)
}
#[inline]
pub fn microsecond(v: f64) -> Time {
Time::new::<time::microsecond>(v)
}
#[inline]
pub fn nanosecond(v: f64) -> Time {
Time::new::<time::nanosecond>(v)
}
use crate::ast::{ComplexAttri, ComplexParseError, SimpleAttri};
use std::ops::Deref;
#[derive(Debug, Default, Clone, Copy)]
#[derive(strum_macros::EnumString, strum_macros::Display)]
pub enum TimeUnit {
#[strum(serialize = "1ps")]
_1ps,
#[strum(serialize = "10ps")]
_10ps,
#[strum(serialize = "100ps")]
_100ps,
#[default]
#[strum(serialize = "1ns")]
_1ns,
}
impl TimeUnit {
const LUT: [<Self as Deref>::Target; 4] = [
Time {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-12,
},
Time {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-11,
},
Time {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-10,
},
Time {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-9,
},
];
}
impl Deref for TimeUnit {
type Target = Time;
#[inline]
fn deref(&self) -> &Self::Target {
&Self::LUT[*self as usize]
}
}
impl SimpleAttri for TimeUnit {}
#[derive(Debug, Default, Clone, Copy)]
#[derive(strum_macros::EnumString, strum_macros::Display)]
pub enum VoltageUnit {
#[strum(serialize = "1mV")]
_1mV,
#[strum(serialize = "10mV")]
_10mV,
#[strum(serialize = "100mV")]
_100mV,
#[default]
#[strum(serialize = "1V")]
_1V,
}
impl VoltageUnit {
const LUT: [<Self as Deref>::Target; 4] = [
ElectricPotential {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-3,
},
ElectricPotential {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-2,
},
ElectricPotential {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-1,
},
ElectricPotential {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E0,
},
];
}
impl Deref for VoltageUnit {
type Target = ElectricPotential;
#[inline]
fn deref(&self) -> &Self::Target {
&Self::LUT[*self as usize]
}
}
impl SimpleAttri for VoltageUnit {}
#[derive(Debug, Clone, Copy)]
#[derive(strum_macros::EnumString, strum_macros::Display)]
pub enum CurrentUnit {
#[strum(serialize = "1uA")]
_1uA,
#[strum(serialize = "10uA")]
_10uA,
#[strum(serialize = "100uA")]
_100uA,
#[strum(serialize = "1mA")]
_1mA,
#[strum(serialize = "10mA")]
_10mA,
#[strum(serialize = "100mA")]
_100mA,
#[strum(serialize = "1A")]
_1A,
}
impl CurrentUnit {
const LUT: [<Self as Deref>::Target; 7] = [
ElectricCurrent {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-6,
},
ElectricCurrent {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-5,
},
ElectricCurrent {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-4,
},
ElectricCurrent {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-3,
},
ElectricCurrent {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-2,
},
ElectricCurrent {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-1,
},
ElectricCurrent {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E0,
},
];
}
impl Deref for CurrentUnit {
type Target = ElectricCurrent;
#[inline]
fn deref(&self) -> &Self::Target {
&Self::LUT[*self as usize]
}
}
impl SimpleAttri for CurrentUnit {}
#[derive(Debug, Clone, Copy)]
#[derive(strum_macros::EnumString, strum_macros::Display)]
pub enum PullingResistanceUnit {
#[strum(serialize = "1ohm")]
_1ohm,
#[strum(serialize = "10ohm")]
_10ohm,
#[strum(serialize = "100ohm")]
_100ohm,
#[strum(serialize = "1kohm")]
_1kohm,
}
impl PullingResistanceUnit {
const LUT: [<Self as Deref>::Target; 4] = [
ElectricalResistance {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E0,
},
ElectricalResistance {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E1,
},
ElectricalResistance {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E2,
},
ElectricalResistance {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E3,
},
];
}
impl Deref for PullingResistanceUnit {
type Target = ElectricalResistance;
#[inline]
fn deref(&self) -> &Self::Target {
&Self::LUT[*self as usize]
}
}
impl SimpleAttri for PullingResistanceUnit {}
#[derive(Debug, Default, Clone, Copy)]
pub struct CapacitiveLoadUnit {
ff_pf: bool,
_v: Capacitance,
}
impl Deref for CapacitiveLoadUnit {
type Target = Capacitance;
#[inline]
fn deref(&self) -> &Self::Target {
&self._v
}
}
impl ComplexAttri for CapacitiveLoadUnit {
fn parse(v: Vec<&str>) -> Result<Self, ComplexParseError> {
let mut i = v.into_iter();
let value: f64 = match i.next() {
Some(s) => match s.parse() {
Ok(f) => f,
Err(e) => return Err(ComplexParseError::Float(e)),
},
None => return Err(ComplexParseError::LengthDismatch),
};
let (ff_pf, _v): (bool, Capacitance) = match i.next() {
Some(s) => match s {
"ff" => (true, Capacitance::new::<capacitance::femtofarad>(value)),
"pf" => (false, Capacitance::new::<capacitance::picofarad>(value)),
_ => return Err(ComplexParseError::UnsupportedWord),
},
None => return Err(ComplexParseError::LengthDismatch),
};
if let Some(_) = i.next() {
return Err(ComplexParseError::LengthDismatch);
}
Ok(Self { ff_pf, _v })
}
fn to_wrapper(&self) -> crate::ast::ComplexWrapper {
let mut buffer = ryu::Buffer::new();
if self.ff_pf {
vec![vec![
buffer.format(self._v.get::<capacitance::femtofarad>()).to_owned(),
"ff".to_owned(),
]]
} else {
vec![vec![
buffer.format(self._v.get::<capacitance::picofarad>()).to_owned(),
"pf".to_owned(),
]]
}
}
}
#[derive(Debug, Clone, Copy)]
#[derive(strum_macros::EnumString, strum_macros::Display)]
pub enum LeakagePowerUnit {
#[strum(serialize = "1pW")]
_1pW,
#[strum(serialize = "10pW")]
_10pW,
#[strum(serialize = "100pW")]
_100pW,
#[strum(serialize = "1nW")]
_1nW,
#[strum(serialize = "10nW")]
_10nW,
#[strum(serialize = "100nW")]
_100nW,
#[strum(serialize = "1mW")]
_1mW,
#[strum(serialize = "10mW")]
_10mW,
#[strum(serialize = "100mW")]
_100mW,
#[strum(serialize = "1W")]
_1W,
}
impl LeakagePowerUnit {
const LUT: [<Self as Deref>::Target; 10] = [
Power {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-12,
},
Power {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-11,
},
Power {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-10,
},
Power {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-9,
},
Power {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-8,
},
Power {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-7,
},
Power {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-3,
},
Power {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-2,
},
Power {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E-1,
},
Power {
dimension: std::marker::PhantomData,
units: std::marker::PhantomData,
value: 1E0,
},
];
}
impl Deref for LeakagePowerUnit {
type Target = Power;
#[inline]
fn deref(&self) -> &Self::Target {
&Self::LUT[*self as usize]
}
}
impl SimpleAttri for LeakagePowerUnit {}