uom/si/
mod.rs

1//! [International System of Units][si] (SI) and [International System of Quantities][isq] (ISQ)
2//! implementations.
3//!
4//! [si]: https://jcgm.bipm.org/vim/en/1.16.html
5//! [isq]: https://jcgm.bipm.org/vim/en/1.6.html
6
7#[macro_use]
8mod prefix;
9
10system! {
11    /// [International System of Quantities](https://jcgm.bipm.org/vim/en/1.6.html) (ISQ).
12    ///
13    /// ## Generic Parameters
14    /// * `L`: Length dimension.
15    /// * `M`: Mass dimension.
16    /// * `T`: Time dimension.
17    /// * `I`: Electric current dimension.
18    /// * `Th`: Thermodynamic temperature dimension.
19    /// * `N`: Amount of substance dimension.
20    /// * `J`: Luminous intensity dimension.
21    /// * `K`: Kind.
22    quantities: ISQ {
23        /// Length, one of the base quantities in the ISQ, denoted by the symbol L. The base unit
24        /// for length is meter in the SI.
25        length: meter, L;
26        /// Mass, one of the base quantities in the ISQ, denoted by the symbol M. The base unit
27        /// for mass is kilogram in the SI.
28        mass: kilogram, M;
29        /// Time, one of the base quantities in the ISQ, denoted by the symbol T. The base unit
30        /// for time is second in the SI.
31        time: second, T;
32        /// Electric current, one of the base quantities in the ISQ, denoted by the symbol I. The
33        /// base unit for electric current is ampere in the SI.
34        electric_current: ampere, I;
35        /// Thermodynamic temperature, one of the base quantities in the ISQ, denoted by the symbol
36        /// Th (Θ). The base unit for thermodynamic temperature is kelvin in the SI.
37        thermodynamic_temperature: kelvin, Th;
38        /// Amount of substance, one of the base quantities in the ISQ, denoted by the symbol N.
39        /// The base unit for amount of substance is mole in the SI.
40        amount_of_substance: mole, N;
41        /// Luminous intensity, one of the base quantities in the ISQ, denoted by the symbol J. The
42        /// base unit for luminous intensity is candela in the SI.
43        luminous_intensity: candela, J;
44    }
45
46    /// [International System of Units](https://jcgm.bipm.org/vim/en/1.16.html) (SI).
47    units: SI {
48        absement::Absement,
49        acceleration::Acceleration,
50        action::Action,
51        amount_of_substance::AmountOfSubstance,
52        angle::Angle,
53        angular_absement::AngularAbsement,
54        angular_acceleration::AngularAcceleration,
55        angular_jerk::AngularJerk,
56        angular_momentum::AngularMomentum,
57        angular_velocity::AngularVelocity,
58        area::Area,
59        areal_density_of_states::ArealDensityOfStates,
60        areal_heat_capacity::ArealHeatCapacity,
61        areal_mass_density::ArealMassDensity,
62        areal_number_density::ArealNumberDensity,
63        areal_number_rate::ArealNumberRate,
64        available_energy::AvailableEnergy,
65        capacitance::Capacitance,
66        catalytic_activity::CatalyticActivity,
67        catalytic_activity_concentration::CatalyticActivityConcentration,
68        curvature::Curvature,
69        diffusion_coefficient::DiffusionCoefficient,
70        dynamic_viscosity::DynamicViscosity,
71        electric_charge::ElectricCharge,
72        electric_charge_areal_density::ElectricChargeArealDensity,
73        electric_charge_linear_density::ElectricChargeLinearDensity,
74        electric_charge_volumetric_density::ElectricChargeVolumetricDensity,
75        electric_current::ElectricCurrent,
76        electric_current_density::ElectricCurrentDensity,
77        electric_dipole_moment::ElectricDipoleMoment,
78        electric_displacement_field::ElectricDisplacementField,
79        electric_field::ElectricField,
80        electric_flux::ElectricFlux,
81        electric_permittivity::ElectricPermittivity,
82        electric_potential::ElectricPotential,
83        electric_quadrupole_moment::ElectricQuadrupoleMoment,
84        electrical_conductance::ElectricalConductance,
85        electrical_conductivity::ElectricalConductivity,
86        electrical_mobility::ElectricalMobility,
87        electrical_resistance::ElectricalResistance,
88        electrical_resistivity::ElectricalResistivity,
89        energy::Energy,
90        force::Force,
91        frequency::Frequency,
92        frequency_drift::FrequencyDrift,
93        heat_capacity::HeatCapacity,
94        heat_flux_density::HeatFluxDensity,
95        heat_transfer::HeatTransfer,
96        inductance::Inductance,
97        information::Information,
98        information_rate::InformationRate,
99        inverse_velocity::InverseVelocity,
100        jerk::Jerk,
101        kinematic_viscosity::KinematicViscosity,
102        length::Length,
103        linear_density_of_states::LinearDensityOfStates,
104        linear_mass_density::LinearMassDensity,
105        linear_number_density::LinearNumberDensity,
106        linear_number_rate::LinearNumberRate,
107        linear_power_density::LinearPowerDensity,
108        luminance::Luminance,
109        luminous_intensity::LuminousIntensity,
110        magnetic_field_strength::MagneticFieldStrength,
111        magnetic_flux::MagneticFlux,
112        magnetic_flux_density::MagneticFluxDensity,
113        magnetic_moment::MagneticMoment,
114        magnetic_permeability::MagneticPermeability,
115        mass::Mass,
116        mass_concentration::MassConcentration,
117        mass_density::MassDensity,
118        mass_flux::MassFlux,
119        mass_per_energy::MassPerEnergy,
120        mass_rate::MassRate,
121        molality::Molality,
122        molar_concentration::MolarConcentration,
123        molar_energy::MolarEnergy,
124        molar_flux::MolarFlux,
125        molar_heat_capacity::MolarHeatCapacity,
126        molar_mass::MolarMass,
127        molar_radioactivity::MolarRadioactivity,
128        molar_volume::MolarVolume,
129        moment_of_inertia::MomentOfInertia,
130        momentum::Momentum,
131        power::Power,
132        power_rate::PowerRate,
133        pressure::Pressure,
134        radiant_exposure::RadiantExposure,
135        radioactivity::Radioactivity,
136        ratio::Ratio,
137        reciprocal_length::ReciprocalLength,
138        solid_angle::SolidAngle,
139        specific_area::SpecificArea,
140        specific_heat_capacity::SpecificHeatCapacity,
141        specific_power::SpecificPower,
142        specific_radioactivity::SpecificRadioactivity,
143        specific_volume::SpecificVolume,
144        surface_electric_current_density::SurfaceElectricCurrentDensity,
145        surface_tension::SurfaceTension,
146        temperature_coefficient::TemperatureCoefficient,
147        temperature_gradient::TemperatureGradient,
148        temperature_interval::TemperatureInterval,
149        thermal_conductance::ThermalConductance,
150        thermal_conductivity::ThermalConductivity,
151        thermal_resistance::ThermalResistance,
152        thermodynamic_temperature::ThermodynamicTemperature,
153        time::Time,
154        torque::Torque,
155        velocity::Velocity,
156        volume::Volume,
157        volume_rate::VolumeRate,
158        volumetric_density_of_states::VolumetricDensityOfStates,
159        volumetric_heat_capacity::VolumetricHeatCapacity,
160        volumetric_number_density::VolumetricNumberDensity,
161        volumetric_number_rate::VolumetricNumberRate,
162        volumetric_power_density::VolumetricPowerDensity,
163    }
164}
165
166/// [`Quantity`] type aliases using the default base units and parameterized
167/// on the underlying storage type.
168pub mod quantities {
169    ISQ!(crate::si);
170}
171
172storage_types! {
173    /// [`Quantity`](crate::si::Quantity) type aliases using the default base units.
174    pub types: All;
175
176    ISQ!(crate::si, V);
177}
178
179/// Primitive traits and types representing basic properties of types specific to the SI.
180pub mod marker {
181    use super::{Dimension, Quantity, Units};
182    use crate::Kind;
183
184    /// `AngleKind` is a `Kind` for separating angular quantities from their identically dimensioned
185    /// non-angular quantity counterparts. Conversions to and from `AngleKind` quantities are
186    /// supported through implementations of the `From` trait.
187    ///
188    #[cfg_attr(feature = "f32", doc = " ```rust")]
189    #[cfg_attr(not(feature = "f32"), doc = " ```rust,ignore")]
190    /// # use uom::si::f32::*;
191    /// # use uom::si::angle::radian;
192    /// let a: Angle = Angle::new::<radian>(1.0);
193    /// let r: Ratio = a.into();
194    /// ```
195    pub trait AngleKind: Kind {}
196
197    /// `SolidAngleKind` is a `Kind` for separating quantities of solid angles from other
198    /// identically dimensioned quantities. Conversions to and from `SolidAngleKind` quantities are
199    /// supported through implementations of the `From` trait.
200    ///
201    #[cfg_attr(feature = "f32", doc = " ```rust")]
202    #[cfg_attr(not(feature = "f32"), doc = " ```rust,ignore")]
203    /// # use uom::si::f32::*;
204    /// # use uom::si::solid_angle::steradian;
205    /// let a: SolidAngle = SolidAngle::new::<steradian>(1.0);
206    /// let r: Ratio = a.into();
207    /// ```
208    pub trait SolidAngleKind: Kind {}
209
210    /// `InformationKind` is a `Kind` for separating information quantities from their identically
211    /// dimensioned non-information quantity counterparts. Conversions to and from `InformationKind`
212    /// quantities are supported through implementations of the `From` trait.
213    ///
214    #[cfg_attr(feature = "f32", doc = " ```rust")]
215    #[cfg_attr(not(feature = "f32"), doc = " ```rust,ignore")]
216    /// # use uom::si::f32::*;
217    /// # use uom::si::information::kilobyte;
218    /// let i: Information = Information::new::<kilobyte>(1.0);
219    /// let r: Ratio = i.into();
220    /// ```
221    pub trait InformationKind: Kind {}
222
223    /// Kind of thermodynamic temperature.
224    pub trait TemperatureKind:
225        crate::marker::Mul
226        + crate::marker::MulAssign
227        + crate::marker::Div
228        + crate::marker::DivAssign
229        + crate::marker::Rem
230        + crate::marker::RemAssign
231    {
232    }
233
234    /// Kind of constituent concentration in chemical mixtures, which separates mass concentration
235    /// from mass density. This `Kind` is also applied to molar concentration and to catalytic
236    /// activity concentration.
237    pub trait ConstituentConcentrationKind: Kind {}
238
239    /// `SurfaceTensionKind` is a `Kind` for separating quantities of surface tension from
240    /// other identically dimensioned quantities. Conversions to and from `SurfaceTensionKind`
241    /// quantities are supported through implementations of the `From` trait.
242    ///
243    #[cfg_attr(feature = "f32", doc = " ```rust")]
244    #[cfg_attr(not(feature = "f32"), doc = " ```rust,ignore")]
245    /// # use uom::si::f32::*;
246    /// # use uom::si::surface_tension::newton_per_meter;
247    /// let st: SurfaceTension = SurfaceTension::new::<newton_per_meter>(1.0);
248    /// let re: RadiantExposure = st.into();
249    /// ```
250    pub trait SurfaceTensionKind: Kind {}
251
252    /// `KinematicViscosityKind` is a `Kind` for separating quantities of
253    /// kinematic viscosity from other identically dimensioned quantities.
254    /// Conversions to and from `KinematicViscosityKind` quantities are
255    /// supported through implementations of the `From` trait.
256    ///
257    #[cfg_attr(feature = "f32", doc = " ```rust")]
258    #[cfg_attr(not(feature = "f32"), doc = " ```rust,ignore")]
259    /// # use uom::si::f32::*;
260    /// # use uom::si::kinematic_viscosity::stokes;
261    /// let kv: KinematicViscosity = KinematicViscosity::new::<stokes>(1.0);
262    /// let dc: DiffusionCoefficient = kv.into();
263    /// ```
264    pub trait KinematicViscosityKind: Kind {}
265
266    /// `impl_from` generates generic inter-Kind implementations of `From`.
267    #[cfg(feature = "autoconvert")]
268    #[macro_export]
269    macro_rules! impl_from {
270        ($a:ident, $b:ident) => {
271            impl<L, M, T, I, Th, N, J, Ul, Ur, V>
272                From<
273                    Quantity<
274                        dyn Dimension<
275                            L = L,
276                            M = M,
277                            T = T,
278                            I = I,
279                            Th = Th,
280                            N = N,
281                            J = J,
282                            Kind = dyn $a,
283                        >,
284                        Ur,
285                        V,
286                    >,
287                >
288                for Quantity<
289                    dyn Dimension<L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = dyn $b>,
290                    Ul,
291                    V,
292                >
293            where
294                L: $crate::typenum::Integer,
295                M: $crate::typenum::Integer,
296                T: $crate::typenum::Integer,
297                I: $crate::typenum::Integer,
298                Th: $crate::typenum::Integer,
299                N: $crate::typenum::Integer,
300                J: $crate::typenum::Integer,
301                Ul: Units<V> + ?Sized,
302                Ur: Units<V> + ?Sized,
303                V: $crate::num_traits::Num + $crate::Conversion<V>,
304            {
305                fn from(
306                    val: Quantity<
307                        dyn Dimension<
308                            L = L,
309                            M = M,
310                            T = T,
311                            I = I,
312                            Th = Th,
313                            N = N,
314                            J = J,
315                            Kind = dyn $a,
316                        >,
317                        Ur,
318                        V,
319                    >,
320                ) -> Quantity<
321                    dyn Dimension<L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = dyn $b>,
322                    Ul,
323                    V,
324                > {
325                    Self {
326                        dimension: $crate::lib::marker::PhantomData,
327                        units: $crate::lib::marker::PhantomData,
328                        value: super::change_base::<
329                            dyn Dimension<
330                                L = L,
331                                M = M,
332                                T = T,
333                                I = I,
334                                Th = Th,
335                                N = N,
336                                J = J,
337                                Kind = dyn $b,
338                            >,
339                            Ul,
340                            Ur,
341                            V,
342                        >(&val.value),
343                    }
344                }
345            }
346        };
347    }
348
349    /// `impl_from` generates generic inter-Kind implementations of `From`.
350    #[cfg(not(feature = "autoconvert"))]
351    #[macro_export]
352    macro_rules! impl_from {
353        ($a:ident, $b:ident) => {
354            impl<L, M, T, I, Th, N, J, U, V>
355                From<
356                    Quantity<
357                        dyn Dimension<
358                            L = L,
359                            M = M,
360                            T = T,
361                            I = I,
362                            Th = Th,
363                            N = N,
364                            J = J,
365                            Kind = dyn $a,
366                        >,
367                        U,
368                        V,
369                    >,
370                >
371                for Quantity<
372                    dyn Dimension<L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = dyn $b>,
373                    U,
374                    V,
375                >
376            where
377                L: $crate::typenum::Integer,
378                M: $crate::typenum::Integer,
379                T: $crate::typenum::Integer,
380                I: $crate::typenum::Integer,
381                Th: $crate::typenum::Integer,
382                N: $crate::typenum::Integer,
383                J: $crate::typenum::Integer,
384                U: Units<V> + ?Sized,
385                V: $crate::num_traits::Num + $crate::Conversion<V>,
386            {
387                fn from(
388                    val: Quantity<
389                        dyn Dimension<
390                            L = L,
391                            M = M,
392                            T = T,
393                            I = I,
394                            Th = Th,
395                            N = N,
396                            J = J,
397                            Kind = dyn $a,
398                        >,
399                        U,
400                        V,
401                    >,
402                ) -> Quantity<
403                    dyn Dimension<L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = dyn $b>,
404                    U,
405                    V,
406                > {
407                    Self {
408                        dimension: $crate::lib::marker::PhantomData,
409                        units: $crate::lib::marker::PhantomData,
410                        value: val.value,
411                    }
412                }
413            }
414        };
415    }
416
417    impl_from!(AngleKind, Kind);
418    impl_from!(Kind, AngleKind);
419    impl_from!(SolidAngleKind, Kind);
420    impl_from!(Kind, SolidAngleKind);
421    impl_from!(InformationKind, Kind);
422    impl_from!(Kind, InformationKind);
423    impl_from!(ConstituentConcentrationKind, Kind);
424    impl_from!(Kind, ConstituentConcentrationKind);
425    impl_from!(SurfaceTensionKind, Kind);
426    impl_from!(Kind, SurfaceTensionKind);
427    impl_from!(KinematicViscosityKind, Kind);
428    impl_from!(Kind, KinematicViscosityKind);
429}