Switched custom quantities to using a macro for generation.
This commit is contained in:
@ -43,58 +43,7 @@ pub trait Quantity<V: Value>: Copy + PartialEq + PartialOrd + Add + Sub {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Value: Num + Copy + PartialOrd + FromPrimitive + NumCast + Display {
|
||||
//----- Temperature ----------------------------------
|
||||
#[inline(always)]
|
||||
fn kelvins(self) -> Kelvins<Self> {
|
||||
Kelvins(self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn deci_kelvins(self) -> DeciKelvins<Self> {
|
||||
DeciKelvins(self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn degrees_celsius(self) -> DegreesCelsius<Self> {
|
||||
DegreesCelsius(self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn deci_degrees_celsius(self) -> DeciDegreesCelsius<Self> {
|
||||
DeciDegreesCelsius(self)
|
||||
}
|
||||
|
||||
//----- Voltage ----------------------------------
|
||||
#[inline(always)]
|
||||
fn volts(self) -> Volts<Self> {
|
||||
Volts(self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn millivolts(self) -> MilliVolts<Self> {
|
||||
MilliVolts(self)
|
||||
}
|
||||
|
||||
//----- Resistance ----------------------------------
|
||||
#[inline(always)]
|
||||
fn ohms(self) -> Ohms<Self> {
|
||||
Ohms(self)
|
||||
}
|
||||
|
||||
//----- Volume rate ----------------------------------
|
||||
#[inline(always)]
|
||||
fn liters_per_minute(self) -> LitersPerMinute<Self> {
|
||||
LitersPerMinute(self)
|
||||
}
|
||||
|
||||
//----- Irradiance ----------------------------------
|
||||
#[inline(always)]
|
||||
fn watts_per_square_meter(self) -> WattsPerSquareMeter<Self> {
|
||||
WattsPerSquareMeter(self)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Value: Num + Copy + PartialOrd + FromPrimitive + NumCast + Display {}
|
||||
impl<V> Value for V where V: Num + Copy + PartialOrd + FromPrimitive + NumCast + Display {}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
@ -161,6 +110,12 @@ mod defmt_impl {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Q: Quantity<usize>> Format for Fmt<usize, Q> {
|
||||
fn format(&self, fmt: Formatter) {
|
||||
write!(fmt, "{} {}", self.quantity.value(), Q::symbol());
|
||||
}
|
||||
}
|
||||
|
||||
impl<Q: Quantity<i8>> Format for Fmt<i8, Q> {
|
||||
fn format(&self, fmt: Formatter) {
|
||||
write!(fmt, "{} {}", self.quantity.value(), Q::symbol());
|
||||
@ -191,6 +146,12 @@ mod defmt_impl {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Q: Quantity<isize>> Format for Fmt<isize, Q> {
|
||||
fn format(&self, fmt: Formatter) {
|
||||
write!(fmt, "{} {}", self.quantity.value(), Q::symbol());
|
||||
}
|
||||
}
|
||||
|
||||
impl<Q: Quantity<f32>> Format for Fmt<f32, Q> {
|
||||
fn format(&self, fmt: Formatter) {
|
||||
write!(fmt, "{} {}", self.quantity.value(), Q::symbol());
|
||||
|
Reference in New Issue
Block a user