Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions proc-macros/src/compute_unit_dimensions_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ pub fn compute_unit_dimensions(input: TokenStream) -> TokenStream {
);

quote! {
(
whippyunits_core::dimension_exponents::DynDimensionExponents([#d0, #d1, #d2, #d3, #d4, #d5, #d6, #d7]),
whippyunits_core::scale_exponents::ScaleExponents([#d8, #d9, #d10, #d11])
)
(#d0, #d1, #d2, #d3, #d4, #d5, #d6, #d7, #d8, #d9, #d10, #d11)
}
.into()
}
296 changes: 144 additions & 152 deletions src/api.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ macro_rules! quantity_quantity_partial_ord_interface {
impl<
$($single_dimension_single_scale_params)*
>
core::cmp::PartialOrd<$crate::quantity_type!($T)>
::core::cmp::PartialOrd<$crate::quantity_type!($T)>
for $crate::quantity_type!($T)
where
$T: PartialOrd,
Brand: PartialEq,
$T: ::core::cmp::PartialOrd,
Brand: ::core::cmp::PartialEq,
{
fn partial_cmp(&self, other: &$crate::quantity_type!($T)) -> Option<::core::cmp::Ordering> {
fn partial_cmp(&self, other: &$crate::quantity_type!($T)) -> ::core::option::Option<::core::cmp::Ordering> {
self.unsafe_value.partial_cmp(&other.unsafe_value)
}
}
Expand Down
211 changes: 150 additions & 61 deletions src/arithmetic_quantity_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,23 @@
#[cfg(has_generic_const_exprs)]
macro_rules! inverse_quantity_type {
($T:ty) => {
Quantity<
Scale<_2<{ -SCALE_P2 }>, _3<{ -SCALE_P3 }>, _5<{ -SCALE_P5 }>, _Pi<{ -SCALE_PI }>>,
Dimension<_M<{ -MASS_EXPONENT }>, _L<{ -LENGTH_EXPONENT }>, _T<{ -TIME_EXPONENT }>, _I<{ -CURRENT_EXPONENT }>, _Θ<{ -TEMPERATURE_EXPONENT }>, _N<{ -AMOUNT_EXPONENT }>, _J<{ -LUMINOSITY_EXPONENT }>, _A<{ -ANGLE_EXPONENT }>>,
$crate::quantity::Quantity<
$crate::quantity::Scale<
$crate::quantity::_2<{ -SCALE_P2 }>,
$crate::quantity::_3<{ -SCALE_P3 }>,
$crate::quantity::_5<{ -SCALE_P5 }>,
$crate::quantity::_Pi<{ -SCALE_PI }>,
>,
$crate::quantity::Dimension<
$crate::quantity::_M<{ -MASS_EXPONENT }>,
$crate::quantity::_L<{ -LENGTH_EXPONENT }>,
$crate::quantity::_T<{ -TIME_EXPONENT }>,
$crate::quantity::_I<{ -CURRENT_EXPONENT }>,
$crate::quantity::_Θ<{ -TEMPERATURE_EXPONENT }>,
$crate::quantity::_N<{ -AMOUNT_EXPONENT }>,
$crate::quantity::_J<{ -LUMINOSITY_EXPONENT }>,
$crate::quantity::_A<{ -ANGLE_EXPONENT }>,
>,
$T,
Brand
>
Expand All @@ -17,17 +31,22 @@ macro_rules! inverse_quantity_type {
#[cfg(not(has_generic_const_exprs))]
macro_rules! inverse_quantity_type {
($T:ty) => {
Quantity<
Scale<_2<INVERSE_SCALE_P2>, _3<INVERSE_SCALE_P3>, _5<INVERSE_SCALE_P5>, _Pi<INVERSE_SCALE_PI>>,
Dimension<
_M<INVERSE_MASS_EXPONENT>,
_L<INVERSE_LENGTH_EXPONENT>,
_T<INVERSE_TIME_EXPONENT>,
_I<INVERSE_CURRENT_EXPONENT>,
_Θ<INVERSE_TEMPERATURE_EXPONENT>,
_N<INVERSE_AMOUNT_EXPONENT>,
_J<INVERSE_LUMINOSITY_EXPONENT>,
_A<INVERSE_ANGLE_EXPONENT>
$crate::quantity::Quantity<
$crate::quantity::Scale<
$crate::quantity::_2<INVERSE_SCALE_P2>,
$crate::quantity::_3<INVERSE_SCALE_P3>,
$crate::quantity::_5<INVERSE_SCALE_P5>,
$crate::quantity::_Pi<INVERSE_SCALE_PI>,
>,
$crate::quantity::Dimension<
$crate::quantity::_M<INVERSE_MASS_EXPONENT>,
$crate::quantity::_L<INVERSE_LENGTH_EXPONENT>,
$crate::quantity::_T<INVERSE_TIME_EXPONENT>,
$crate::quantity::_I<INVERSE_CURRENT_EXPONENT>,
$crate::quantity::_Θ<INVERSE_TEMPERATURE_EXPONENT>,
$crate::quantity::_N<INVERSE_AMOUNT_EXPONENT>,
$crate::quantity::_J<INVERSE_LUMINOSITY_EXPONENT>,
$crate::quantity::_A<INVERSE_ANGLE_EXPONENT>,
>,
$T,
Brand
Expand All @@ -39,25 +58,67 @@ macro_rules! inverse_quantity_type {
#[doc(hidden)]
macro_rules! addition_input {
(Strict, $T:ty) => {
Quantity<
Scale<_2<SCALE_P2>, _3<SCALE_P3>, _5<SCALE_P5>, _Pi<SCALE_PI>>,
Dimension<_M<MASS_EXPONENT>, _L<LENGTH_EXPONENT>, _T<TIME_EXPONENT>, _I<CURRENT_EXPONENT>, _Θ<TEMPERATURE_EXPONENT>, _N<AMOUNT_EXPONENT>, _J<LUMINOSITY_EXPONENT>, _A<ANGLE_EXPONENT>>,
$crate::quantity::Quantity<
$crate::quantity::Scale<
$crate::quantity::_2<SCALE_P2>,
$crate::quantity::_3<SCALE_P3>,
$crate::quantity::_5<SCALE_P5>,
$crate::quantity::_Pi<SCALE_PI>,
>,
$crate::quantity::Dimension<
$crate::quantity::_M<MASS_EXPONENT>,
$crate::quantity::_L<LENGTH_EXPONENT>,
$crate::quantity::_T<TIME_EXPONENT>,
$crate::quantity::_I<CURRENT_EXPONENT>,
$crate::quantity::_Θ<TEMPERATURE_EXPONENT>,
$crate::quantity::_N<AMOUNT_EXPONENT>,
$crate::quantity::_J<LUMINOSITY_EXPONENT>,
$crate::quantity::_A<ANGLE_EXPONENT>,
>,
$T,
Brand
>
};
(LeftHand, $T:ty) => {
Quantity<
Scale<_2<SCALE_P2_1>, _3<SCALE_P3_1>, _5<SCALE_P5_1>, _Pi<SCALE_PI_1>>,
Dimension<_M<MASS_EXPONENT>, _L<LENGTH_EXPONENT>, _T<TIME_EXPONENT>, _I<CURRENT_EXPONENT>, _Θ<TEMPERATURE_EXPONENT>, _N<AMOUNT_EXPONENT>, _J<LUMINOSITY_EXPONENT>, _A<ANGLE_EXPONENT>>,
$crate::quantity::Quantity<
$crate::quantity::Scale<
$crate::quantity::_2<SCALE_P2_1>,
$crate::quantity::_3<SCALE_P3_1>,
$crate::quantity::_5<SCALE_P5_1>,
$crate::quantity::_Pi<SCALE_PI_1>,
>,
$crate::quantity::Dimension<
$crate::quantity::_M<MASS_EXPONENT>,
$crate::quantity::_L<LENGTH_EXPONENT>,
$crate::quantity::_T<TIME_EXPONENT>,
$crate::quantity::_I<CURRENT_EXPONENT>,
$crate::quantity::_Θ<TEMPERATURE_EXPONENT>,
$crate::quantity::_N<AMOUNT_EXPONENT>,
$crate::quantity::_J<LUMINOSITY_EXPONENT>,
$crate::quantity::_A<ANGLE_EXPONENT>,
>,
$T,
Brand
>
};
(RightHand, $T:ty) => {
Quantity<
Scale<_2<SCALE_P2_2>, _3<SCALE_P3_2>, _5<SCALE_P5_2>, _Pi<SCALE_PI_2>>,
Dimension<_M<MASS_EXPONENT>, _L<LENGTH_EXPONENT>, _T<TIME_EXPONENT>, _I<CURRENT_EXPONENT>, _Θ<TEMPERATURE_EXPONENT>, _N<AMOUNT_EXPONENT>, _J<LUMINOSITY_EXPONENT>, _A<ANGLE_EXPONENT>>,
$crate::quantity::Quantity<
$crate::quantity::Scale<
$crate::quantity::_2<SCALE_P2_2>,
$crate::quantity::_3<SCALE_P3_2>,
$crate::quantity::_5<SCALE_P5_2>,
$crate::quantity::_Pi<SCALE_PI_2>,
>,
$crate::quantity::Dimension<
$crate::quantity::_M<MASS_EXPONENT>,
$crate::quantity::_L<LENGTH_EXPONENT>,
$crate::quantity::_T<TIME_EXPONENT>,
$crate::quantity::_I<CURRENT_EXPONENT>,
$crate::quantity::_Θ<TEMPERATURE_EXPONENT>,
$crate::quantity::_N<AMOUNT_EXPONENT>,
$crate::quantity::_J<LUMINOSITY_EXPONENT>,
$crate::quantity::_A<ANGLE_EXPONENT>,
>,
$T,
Brand
>
Expand All @@ -68,17 +129,45 @@ macro_rules! addition_input {
#[doc(hidden)]
macro_rules! multiplication_input {
(LeftHand, $T:ty) => {
Quantity<
Scale<_2<SCALE_P2_1>, _3<SCALE_P3_1>, _5<SCALE_P5_1>, _Pi<SCALE_PI_1>>,
Dimension<_M<MASS_EXPONENT_1>, _L<LENGTH_EXPONENT_1>, _T<TIME_EXPONENT_1>, _I<CURRENT_EXPONENT_1>, _Θ<TEMPERATURE_EXPONENT_1>, _N<AMOUNT_EXPONENT_1>, _J<LUMINOSITY_EXPONENT_1>, _A<ANGLE_EXPONENT_1>>,
$crate::quantity::Quantity<
$crate::quantity::Scale<
$crate::quantity::_2<SCALE_P2_1>,
$crate::quantity::_3<SCALE_P3_1>,
$crate::quantity::_5<SCALE_P5_1>,
$crate::quantity::_Pi<SCALE_PI_1>,
>,
$crate::quantity::Dimension<
$crate::quantity::_M<MASS_EXPONENT_1>,
$crate::quantity::_L<LENGTH_EXPONENT_1>,
$crate::quantity::_T<TIME_EXPONENT_1>,
$crate::quantity::_I<CURRENT_EXPONENT_1>,
$crate::quantity::_Θ<TEMPERATURE_EXPONENT_1>,
$crate::quantity::_N<AMOUNT_EXPONENT_1>,
$crate::quantity::_J<LUMINOSITY_EXPONENT_1>,
$crate::quantity::_A<ANGLE_EXPONENT_1>,
>,
$T,
Brand
>
};
(RightHand, $T:ty) => {
Quantity<
Scale<_2<SCALE_P2_2>, _3<SCALE_P3_2>, _5<SCALE_P5_2>, _Pi<SCALE_PI_2>>,
Dimension<_M<MASS_EXPONENT_2>, _L<LENGTH_EXPONENT_2>, _T<TIME_EXPONENT_2>, _I<CURRENT_EXPONENT_2>, _Θ<TEMPERATURE_EXPONENT_2>, _N<AMOUNT_EXPONENT_2>, _J<LUMINOSITY_EXPONENT_2>, _A<ANGLE_EXPONENT_2>>,
$crate::quantity::Quantity<
$crate::quantity::Scale<
$crate::quantity::_2<SCALE_P2_2>,
$crate::quantity::_3<SCALE_P3_2>,
$crate::quantity::_5<SCALE_P5_2>,
$crate::quantity::_Pi<SCALE_PI_2>,
>,
$crate::quantity::Dimension<
$crate::quantity::_M<MASS_EXPONENT_2>,
$crate::quantity::_L<LENGTH_EXPONENT_2>,
$crate::quantity::_T<TIME_EXPONENT_2>,
$crate::quantity::_I<CURRENT_EXPONENT_2>,
$crate::quantity::_Θ<TEMPERATURE_EXPONENT_2>,
$crate::quantity::_N<AMOUNT_EXPONENT_2>,
$crate::quantity::_J<LUMINOSITY_EXPONENT_2>,
$crate::quantity::_A<ANGLE_EXPONENT_2>,
>,
$T,
Brand
>
Expand All @@ -90,22 +179,22 @@ macro_rules! multiplication_input {
#[cfg(has_generic_const_exprs)]
macro_rules! multiplication_output {
($T:ty, $log_op:tt) => {
Quantity<
Scale<
_2<{ SCALE_P2_1 $log_op SCALE_P2_2 }>,
_3<{ SCALE_P3_1 $log_op SCALE_P3_2 }>,
_5<{ SCALE_P5_1 $log_op SCALE_P5_2 }>,
_Pi<{ SCALE_PI_1 $log_op SCALE_PI_2 }>
>,
Dimension<
_M<{ MASS_EXPONENT_1 $log_op MASS_EXPONENT_2 }>,
_L<{ LENGTH_EXPONENT_1 $log_op LENGTH_EXPONENT_2 }>,
_T<{ TIME_EXPONENT_1 $log_op TIME_EXPONENT_2 }>,
_I<{ CURRENT_EXPONENT_1 $log_op CURRENT_EXPONENT_2 }>,
_Θ<{ TEMPERATURE_EXPONENT_1 $log_op TEMPERATURE_EXPONENT_2 }>,
_N<{ AMOUNT_EXPONENT_1 $log_op AMOUNT_EXPONENT_2 }>,
_J<{ LUMINOSITY_EXPONENT_1 $log_op LUMINOSITY_EXPONENT_2 }>,
_A<{ ANGLE_EXPONENT_1 $log_op ANGLE_EXPONENT_2 }>
$crate::quantity::Quantity<
$crate::quantity::Scale<
$crate::quantity::_2<{ SCALE_P2_1 $log_op SCALE_P2_2 }>,
$crate::quantity::_3<{ SCALE_P3_1 $log_op SCALE_P3_2 }>,
$crate::quantity::_5<{ SCALE_P5_1 $log_op SCALE_P5_2 }>,
$crate::quantity::_Pi<{ SCALE_PI_1 $log_op SCALE_PI_2 }>,
>,
$crate::quantity::Dimension<
$crate::quantity::_M<{ MASS_EXPONENT_1 $log_op MASS_EXPONENT_2 }>,
$crate::quantity::_L<{ LENGTH_EXPONENT_1 $log_op LENGTH_EXPONENT_2 }>,
$crate::quantity::_T<{ TIME_EXPONENT_1 $log_op TIME_EXPONENT_2 }>,
$crate::quantity::_I<{ CURRENT_EXPONENT_1 $log_op CURRENT_EXPONENT_2 }>,
$crate::quantity::_Θ<{ TEMPERATURE_EXPONENT_1 $log_op TEMPERATURE_EXPONENT_2 }>,
$crate::quantity::_N<{ AMOUNT_EXPONENT_1 $log_op AMOUNT_EXPONENT_2 }>,
$crate::quantity::_J<{ LUMINOSITY_EXPONENT_1 $log_op LUMINOSITY_EXPONENT_2 }>,
$crate::quantity::_A<{ ANGLE_EXPONENT_1 $log_op ANGLE_EXPONENT_2 }>,
>,
$T,
Brand
Expand All @@ -118,22 +207,22 @@ macro_rules! multiplication_output {
#[cfg(not(has_generic_const_exprs))]
macro_rules! multiplication_output {
($T:ty, $log_op:tt) => {
Quantity<
Scale<
_2<SCALE_P2>,
_3<SCALE_P3>,
_5<SCALE_P5>,
_Pi<SCALE_PI>
>,
Dimension<
_M<MASS_EXPONENT>,
_L<LENGTH_EXPONENT>,
_T<TIME_EXPONENT>,
_I<CURRENT_EXPONENT>,
_Θ<TEMPERATURE_EXPONENT>,
_N<AMOUNT_EXPONENT>,
_J<LUMINOSITY_EXPONENT>,
_A<ANGLE_EXPONENT>
$crate::quantity::Quantity<
$crate::quantity::Scale<
$crate::quantity::_2<SCALE_P2>,
$crate::quantity::_3<SCALE_P3>,
$crate::quantity::_5<SCALE_P5>,
$crate::quantity::_Pi<SCALE_PI>,
>,
$crate::quantity::Dimension<
$crate::quantity::_M<MASS_EXPONENT>,
$crate::quantity::_L<LENGTH_EXPONENT>,
$crate::quantity::_T<TIME_EXPONENT>,
$crate::quantity::_I<CURRENT_EXPONENT>,
$crate::quantity::_Θ<TEMPERATURE_EXPONENT>,
$crate::quantity::_N<AMOUNT_EXPONENT>,
$crate::quantity::_J<LUMINOSITY_EXPONENT>,
$crate::quantity::_A<ANGLE_EXPONENT>,
>,
$T,
Brand
Expand Down
30 changes: 16 additions & 14 deletions src/dimension_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@
//! (`D1` and `D2`), and so must be done in the function. There is no way to assert on the trait itself
//! that "this type can be added to any other type that also represents a length".

use crate::quantity::Quantity;
use crate::quantity::{_2, _3, _5, _A, _I, _J, _L, _M, _N, _Pi, _T, _Θ, Dimension, Scale};

/// Expands to a trait and its implementation for a specific atomic dimension.
/// It follows the same pattern as the default declarators but focuses only on the
/// trait definition and implementation for scale-generic quantities.
Expand All @@ -73,17 +70,22 @@ macro_rules! define_atomic_dimension_trait {

impl<const SCALE_P2: i16, const SCALE_P3: i16, const SCALE_P5: i16, const SCALE_PI: i16, T>
$trait_name
for Quantity<
Scale<_2<SCALE_P2>, _3<SCALE_P3>, _5<SCALE_P5>, _Pi<SCALE_PI>>,
Dimension<
_M<$mass_exp>,
_L<$length_exp>,
_T<$time_exp>,
_I<$current_exp>,
_Θ<$temperature_exp>,
_N<$amount_exp>,
_J<$luminosity_exp>,
_A<$angle_exp>,
for $crate::quantity::Quantity<
$crate::quantity::Scale<
$crate::quantity::_2<SCALE_P2>,
$crate::quantity::_3<SCALE_P3>,
$crate::quantity::_5<SCALE_P5>,
$crate::quantity::_Pi<SCALE_PI>,
>,
$crate::quantity::Dimension<
$crate::quantity::_M<$mass_exp>,
$crate::quantity::_L<$length_exp>,
$crate::quantity::_T<$time_exp>,
$crate::quantity::_I<$current_exp>,
$crate::quantity::_Θ<$temperature_exp>,
$crate::quantity::_N<$amount_exp>,
$crate::quantity::_J<$luminosity_exp>,
$crate::quantity::_A<$angle_exp>,
>,
T,
>
Expand Down
Loading