use crate::{dimension::Dimensions, scalar::Scalar};
use core::marker::PhantomData;
mod cmp;
mod convert;
mod fmt;
mod ops;
pub mod kind;
pub use fmt::UnitDisplay;
#[repr(transparent)]
pub struct Quantity<S, D, K = kind::Anon>
where
S: Scalar,
D: Dimensions,
{
pub(crate) value: S,
_phantom: PhantomData<(D, K)>,
}
impl<S, D, K> Quantity<S, D, K>
where
S: Scalar,
D: Dimensions,
{
#[inline(always)]
pub const fn from_base(value: S) -> Self {
Self {
value,
_phantom: PhantomData,
}
}
#[inline(always)]
pub const fn value(&self) -> S {
self.value
}
#[inline(always)]
pub const fn cast_kind<K2>(self) -> Quantity<S, D, K2> {
Quantity {
value: self.value,
_phantom: PhantomData,
}
}
#[inline(always)]
pub const fn erase_kind(self) -> Quantity<S, D, kind::Anon> {
self.cast_kind()
}
}
impl<S, D, K> Clone for Quantity<S, D, K>
where
S: Scalar,
D: Dimensions,
{
fn clone(&self) -> Self {
*self
}
}
impl<S, D, K> Copy for Quantity<S, D, K>
where
S: Scalar,
D: Dimensions,
{
}
impl<S, D, K> core::fmt::Debug for Quantity<S, D, K>
where
S: Scalar,
D: Dimensions,
{
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Quantity({:?})", self.value)
}
}
#[cfg(feature = "f32")]
const _: () = assert!(
core::mem::size_of::<Quantity<f32, crate::dimension::Dimensionless>>()
== core::mem::size_of::<f32>()
);
#[cfg(feature = "f64")]
const _: () = assert!(
core::mem::size_of::<Quantity<f64, crate::dimension::Dimensionless>>()
== core::mem::size_of::<f64>()
);