use crate::dimension::Dimension;
use std::fmt;
#[derive(Clone, Copy, PartialEq)]
pub struct BaseUnit {
pub name: &'static str,
pub symbol: &'static str,
pub aliases: &'static [&'static str],
pub dimension: Dimension,
pub scale: f64,
pub offset: f64,
}
impl BaseUnit {
pub const fn new(
name: &'static str,
symbol: &'static str,
aliases: &'static [&'static str],
dimension: Dimension,
scale: f64,
) -> Self {
BaseUnit {
name,
symbol,
aliases,
dimension,
scale,
offset: 0.0,
}
}
pub const fn with_offset(
name: &'static str,
symbol: &'static str,
aliases: &'static [&'static str],
dimension: Dimension,
scale: f64,
offset: f64,
) -> Self {
BaseUnit {
name,
symbol,
aliases,
dimension,
scale,
offset,
}
}
}
impl BaseUnit {
pub const fn dimension(&self) -> Dimension {
self.dimension
}
pub fn pow(&self, exp: impl Into<crate::dimension::Rational16>) -> crate::Unit {
crate::Unit::from(*self).pow(exp)
}
}
impl fmt::Debug for BaseUnit {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "BaseUnit({})", self.symbol)
}
}
impl fmt::Display for BaseUnit {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.symbol)
}
}