use super::{UnitBi, UnitSi};
#[cfg(feature = "alloc")]
use crate::data::Vec;
#[doc = crate::_tags!(num)]
#[doc = crate::_doc_location!("phys/unit")]
pub trait Unit: Sized {
#[must_use]
fn symbol(&self) -> &str;
#[must_use]
fn symbol_ascii(&self) -> &str;
#[must_use]
fn name(&self) -> &str;
#[must_use]
fn factor(&self) -> f64;
#[must_use]
fn factor_i64(&self) -> i64;
#[must_use]
fn factor_i128(&self) -> i128;
fn asc_iter() -> impl Iterator<Item = Self>;
fn desc_iter() -> impl Iterator<Item = Self>;
const BASE: Option<i32> = None;
#[must_use]
fn exp(&self) -> Option<i32> {
None
}
#[must_use]
fn convert(value: f64, from: Self, to: Self) -> f64;
#[must_use]
fn convert_i64(value: i64, from: Self, to: Self) -> (i64, i64);
#[must_use]
fn convert_i128(value: i128, from: Self, to: Self) -> (i128, i128);
#[must_use]
fn reduce(value: f64) -> (f64, Self);
#[must_use]
fn reduce_i64(value: i64) -> (i64, Self, i64);
#[must_use]
fn reduce_i128(value: i128) -> (i128, Self, i128);
#[must_use]
#[cfg(feature = "alloc")]
fn reduce_chain(value: f64, threshold: f64) -> Vec<(f64, Self)>;
#[must_use]
#[cfg(feature = "alloc")]
fn reduce_chain_i64(value: i64, threshold: i64) -> Vec<(i64, Self)>;
#[must_use]
#[cfg(feature = "alloc")]
fn reduce_chain_i128(value: i128, threshold: i128) -> Vec<(i128, Self)>;
}
macro_rules! impl_unit {
($($t:ty),+) => { $( impl_unit![@$t]; )+ };
(@$t:ty) => {
impl Unit for $t {
fn symbol(&self) -> &str { self.symbol() }
fn symbol_ascii(&self) -> &str { self.symbol_ascii() }
fn name(&self) -> &str { self.name() }
fn factor(&self) -> f64 { self.factor() }
fn factor_i64(&self) -> i64 { self.factor_i64() }
fn factor_i128(&self) -> i128 { self.factor_i128() }
fn asc_iter() -> impl Iterator<Item = Self> { Self::asc_iter() }
fn desc_iter() -> impl Iterator<Item = Self> { Self::desc_iter() }
const BASE: Option<i32> = Some(Self::BASE);
fn exp(&self) -> Option<i32> { Some(self.exp()) }
fn convert(value: f64, from: Self, to: Self) -> f64 {
Self::convert(value, from, to)
}
fn convert_i64(value: i64, from: Self, to: Self) -> (i64, i64) {
Self::convert_i64(value, from, to)
}
fn convert_i128(value: i128, from: Self, to: Self) -> (i128, i128) {
Self::convert_i128(value, from, to)
}
fn reduce(value: f64) -> (f64, Self) { Self::reduce(value) }
fn reduce_i64(value: i64) -> (i64, Self, i64) { Self::reduce_i64(value) }
fn reduce_i128(value: i128) -> (i128, Self, i128){ Self::reduce_i128(value) }
#[cfg(feature = "alloc")]
fn reduce_chain(value: f64, threshold: f64) -> Vec<(f64, Self)> {
Self::reduce_chain(value, threshold)
}
#[cfg(feature = "alloc")]
fn reduce_chain_i64(value: i64, threshold: i64) -> Vec<(i64, Self)> {
Self::reduce_chain_i64(value, threshold)
}
#[cfg(feature = "alloc")]
fn reduce_chain_i128(value: i128, threshold: i128) -> Vec<(i128, Self)> {
Self::reduce_chain_i128(value, threshold)
}
}
};
}
impl_unit![UnitBi, UnitSi];