unitforge 0.3.13__tar.gz → 0.3.15__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {unitforge-0.3.13 → unitforge-0.3.15}/Cargo.lock +6 -6
- {unitforge-0.3.13 → unitforge-0.3.15}/Cargo.toml +4 -4
- {unitforge-0.3.13 → unitforge-0.3.15}/PKG-INFO +1 -1
- {unitforge-0.3.13 → unitforge-0.3.15}/src/impl_macros.rs +37 -2
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/acceleration.rs +1 -15
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/angle.rs +2 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/angular_acceleration.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/angular_velocity.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/area.rs +1 -15
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/area_of_moment.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/charge.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/compliance.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/density.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/distance.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/force.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/force_area.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/force_distance.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/force_div_distance_power_four.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/force_per_volume.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/force_stress.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/force_volume.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/inverse_area.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/inverse_distance.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/inverse_stress.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/mass.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/mass_div_time_squared_volume.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/mass_per_distance.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/rotational_stiffness.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/stiffness.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/strain.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/stress.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/stress_squared.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/time.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/velocity.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/velocity_squared.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/voltage.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities/volume.rs +1 -14
- {unitforge-0.3.13 → unitforge-0.3.15}/src/tests/quantity_unit_tests.rs +22 -1
- {unitforge-0.3.13 → unitforge-0.3.15}/unitforge_macros/Cargo.toml +1 -1
- {unitforge-0.3.13 → unitforge-0.3.15}/unitforge_macros/src/lib.rs +76 -5
- {unitforge-0.3.13 → unitforge-0.3.15}/.gitignore +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/.gitlab-ci.yml +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/Readme.md +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/Readme_py.md +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/pyproject.toml +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/python/unitforge/__init__.py +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/scripts/generate_python_stubs.py +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/src/lib.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/src/prelude.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/src/quantities.template.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/src/relations.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/src/small_linalg/bindings/matrix3_py.template.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/src/small_linalg/bindings/vector3_py.template.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/src/small_linalg/matrix2.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/src/small_linalg/matrix2x3.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/src/small_linalg/matrix3.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/src/small_linalg/matrix3x2.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/src/small_linalg/vector2.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/src/small_linalg/vector3.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/src/tests/serde_tests.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/tests/matrix2.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/tests/matrix2x3.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/tests/matrix3.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/tests/matrix3x2.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/tests/ndarray_dot.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/tests/quantities.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/tests/small_linalg_interfaces.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/tests/test_quantities.py +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/tests/test_small_linalg.py +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/tests/typecheck/mypy_smoke.py +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/tests/vector2.rs +0 -0
- {unitforge-0.3.13 → unitforge-0.3.15}/tests/vector3.rs +0 -0
|
@@ -322,15 +322,15 @@ dependencies = [
|
|
|
322
322
|
|
|
323
323
|
[[package]]
|
|
324
324
|
name = "strum"
|
|
325
|
-
version = "0.
|
|
325
|
+
version = "0.28.0"
|
|
326
326
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
327
|
-
checksum = "
|
|
327
|
+
checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd"
|
|
328
328
|
|
|
329
329
|
[[package]]
|
|
330
330
|
name = "strum_macros"
|
|
331
|
-
version = "0.
|
|
331
|
+
version = "0.28.0"
|
|
332
332
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
333
|
-
checksum = "
|
|
333
|
+
checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664"
|
|
334
334
|
dependencies = [
|
|
335
335
|
"heck",
|
|
336
336
|
"proc-macro2",
|
|
@@ -369,7 +369,7 @@ checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
|
|
|
369
369
|
|
|
370
370
|
[[package]]
|
|
371
371
|
name = "unitforge"
|
|
372
|
-
version = "0.3.
|
|
372
|
+
version = "0.3.15"
|
|
373
373
|
dependencies = [
|
|
374
374
|
"ndarray",
|
|
375
375
|
"num-traits",
|
|
@@ -384,7 +384,7 @@ dependencies = [
|
|
|
384
384
|
|
|
385
385
|
[[package]]
|
|
386
386
|
name = "unitforge_macros"
|
|
387
|
-
version = "0.3.
|
|
387
|
+
version = "0.3.15"
|
|
388
388
|
dependencies = [
|
|
389
389
|
"regex",
|
|
390
390
|
]
|
|
@@ -4,7 +4,7 @@ crate-type = ["cdylib", "rlib"]
|
|
|
4
4
|
|
|
5
5
|
[package]
|
|
6
6
|
name = "unitforge"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.15"
|
|
8
8
|
edition = "2021"
|
|
9
9
|
authors = ["Dr.Q team <info@askdrq.com>", "Henrik Stromberg <henrik@askdrq.com>"]
|
|
10
10
|
description = "A library for unit and quantity consistent computations in Rust"
|
|
@@ -21,9 +21,9 @@ serde = { version = "1", optional = true, features = ["derive"] }
|
|
|
21
21
|
serde_json = { version = "1.0.140", optional = true }
|
|
22
22
|
pyo3 = { version = "0.26.0", features = ["extension-module", "auto-initialize", "multiple-pymethods"], optional = true }
|
|
23
23
|
numpy = { version = "0.26.0", optional = true }
|
|
24
|
-
strum = { version = "0.
|
|
25
|
-
strum_macros = { version = "0.
|
|
26
|
-
unitforge_macros = { version = "0.3.
|
|
24
|
+
strum = { version = "0.28.0", optional = true }
|
|
25
|
+
strum_macros = { version = "0.28.0", optional = true }
|
|
26
|
+
unitforge_macros = { version = "0.3.15", path = "unitforge_macros" }
|
|
27
27
|
|
|
28
28
|
[features]
|
|
29
29
|
serde = ["dep:serde", "dep:serde_json", "ndarray/serde"]
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
#[macro_export]
|
|
2
2
|
macro_rules! impl_quantity {
|
|
3
3
|
($type:ident, $unit:ident, $display_units:expr) => {
|
|
4
|
+
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
5
|
+
use num_traits::Zero;
|
|
6
|
+
use std::collections::HashSet;
|
|
7
|
+
use num_traits::{Float, FromPrimitive};
|
|
8
|
+
#[cfg(feature = "serde")]
|
|
9
|
+
use serde::{Deserialize, Serialize};
|
|
10
|
+
use std::cmp::Ordering;
|
|
11
|
+
use std::fmt;
|
|
12
|
+
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
+
use $crate::prelude::*;
|
|
14
|
+
|
|
15
|
+
#[cfg(feature = "pyo3")]
|
|
16
|
+
use pyo3::pyclass;
|
|
4
17
|
#[cfg(feature = "pyo3")]
|
|
5
18
|
use pyo3::{
|
|
6
19
|
basic::CompareOp, exceptions::PyValueError, pymethods, types::PyType, Bound,
|
|
@@ -9,6 +22,8 @@ macro_rules! impl_quantity {
|
|
|
9
22
|
|
|
10
23
|
#[cfg(feature = "strum")]
|
|
11
24
|
use strum::IntoEnumIterator;
|
|
25
|
+
#[cfg(feature = "strum")]
|
|
26
|
+
use strum_macros::EnumIter;
|
|
12
27
|
use $crate::small_linalg::{Matrix3, Vector3};
|
|
13
28
|
#[cfg(feature = "pyo3")]
|
|
14
29
|
use $crate::Quantity;
|
|
@@ -581,10 +596,30 @@ macro_rules! impl_quantity {
|
|
|
581
596
|
|
|
582
597
|
#[cfg(feature = "strum")]
|
|
583
598
|
impl $type {
|
|
584
|
-
pub fn optimal_unit(
|
|
599
|
+
pub fn optimal_unit(
|
|
600
|
+
&self,
|
|
601
|
+
choices: impl Into<Option<HashSet<$unit>>>,
|
|
602
|
+
) -> Option<$unit> {
|
|
603
|
+
let choices = choices.into().unwrap_or_else(|| $unit::iter().collect());
|
|
604
|
+
let mut min_value = f64::INFINITY;
|
|
605
|
+
let mut best_unit = None;
|
|
606
|
+
for unit in choices {
|
|
607
|
+
let deviation = (self.to(unit).abs() - 1.).abs();
|
|
608
|
+
if deviation < min_value {
|
|
609
|
+
min_value = deviation;
|
|
610
|
+
best_unit = Some(unit);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
best_unit
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
#[cfg(not(feature = "strum"))]
|
|
618
|
+
impl $type {
|
|
619
|
+
pub fn optimal_unit(&self, choices: HashSet<$unit>) -> Option<$unit> {
|
|
585
620
|
let mut min_value = f64::INFINITY;
|
|
586
621
|
let mut best_unit = None;
|
|
587
|
-
for unit in
|
|
622
|
+
for unit in choices {
|
|
588
623
|
let deviation = (self.to(unit).abs() - 1.).abs();
|
|
589
624
|
if deviation < min_value {
|
|
590
625
|
min_value = deviation;
|
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
|
|
14
|
-
#[cfg(feature = "strum")]
|
|
15
|
-
use strum_macros::EnumIter;
|
|
16
2
|
|
|
17
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
18
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
19
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
20
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
21
7
|
pub enum AccelerationUnit {
|
|
22
8
|
m_ssq,
|
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
2
|
use crate::PhysicsUnit;
|
|
4
|
-
use
|
|
5
|
-
use num_traits::identities::Zero;
|
|
6
|
-
use num_traits::{Float, FloatConst, FromPrimitive};
|
|
7
|
-
#[cfg(feature = "pyo3")]
|
|
8
|
-
use pyo3::pyclass;
|
|
9
|
-
#[cfg(feature = "serde")]
|
|
10
|
-
use serde::{Deserialize, Serialize};
|
|
11
|
-
use std::cmp::Ordering;
|
|
3
|
+
use num_traits::FloatConst;
|
|
12
4
|
use std::f64::consts::PI;
|
|
13
|
-
use std::fmt;
|
|
14
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
15
|
-
#[cfg(feature = "strum")]
|
|
16
|
-
use strum_macros::EnumIter;
|
|
17
5
|
|
|
18
6
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
19
7
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
20
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
8
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
21
9
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
22
10
|
pub enum AngleUnit {
|
|
23
11
|
rad,
|
|
@@ -1,23 +1,10 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
2
|
use crate::PhysicsUnit;
|
|
4
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
5
|
-
use num_traits::identities::Zero;
|
|
6
|
-
use num_traits::{Float, FromPrimitive};
|
|
7
|
-
#[cfg(feature = "pyo3")]
|
|
8
|
-
use pyo3::pyclass;
|
|
9
|
-
#[cfg(feature = "serde")]
|
|
10
|
-
use serde::{Deserialize, Serialize};
|
|
11
|
-
use std::cmp::Ordering;
|
|
12
3
|
use std::f64::consts::PI;
|
|
13
|
-
use std::fmt;
|
|
14
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
15
|
-
#[cfg(feature = "strum")]
|
|
16
|
-
use strum_macros::EnumIter;
|
|
17
4
|
|
|
18
5
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
19
6
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
20
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
7
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
21
8
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
22
9
|
pub enum AngularAccelerationUnit {
|
|
23
10
|
rad_ssq,
|
|
@@ -1,23 +1,10 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
2
|
use crate::PhysicsUnit;
|
|
4
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
5
|
-
use num_traits::identities::Zero;
|
|
6
|
-
use num_traits::{Float, FromPrimitive};
|
|
7
|
-
#[cfg(feature = "pyo3")]
|
|
8
|
-
use pyo3::pyclass;
|
|
9
|
-
#[cfg(feature = "serde")]
|
|
10
|
-
use serde::{Deserialize, Serialize};
|
|
11
|
-
use std::cmp::Ordering;
|
|
12
3
|
use std::f64::consts::PI;
|
|
13
|
-
use std::fmt;
|
|
14
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
15
|
-
#[cfg(feature = "strum")]
|
|
16
|
-
use strum_macros::EnumIter;
|
|
17
4
|
|
|
18
5
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
19
6
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
20
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
7
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
21
8
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
22
9
|
pub enum AngularVelocityUnit {
|
|
23
10
|
rad_s,
|
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
|
|
14
|
-
#[cfg(feature = "strum")]
|
|
15
|
-
use strum_macros::EnumIter;
|
|
16
2
|
|
|
17
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
18
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
19
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
20
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
21
7
|
pub enum AreaUnit {
|
|
22
8
|
kmsq,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum AreaOfMomentUnit {
|
|
21
8
|
mhc,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum ChargeUnit {
|
|
21
8
|
C,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum ComplianceUnit {
|
|
21
8
|
m_N,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum DensityUnit {
|
|
21
8
|
kg_dmcb,
|
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
2
|
use crate::quantities::*;
|
|
4
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
5
|
-
use num_traits::identities::Zero;
|
|
6
|
-
use num_traits::{Float, FromPrimitive};
|
|
7
|
-
#[cfg(feature = "pyo3")]
|
|
8
|
-
use pyo3::pyclass;
|
|
9
|
-
#[cfg(feature = "serde")]
|
|
10
|
-
use serde::{Deserialize, Serialize};
|
|
11
|
-
use std::cmp::Ordering;
|
|
12
|
-
use std::fmt;
|
|
13
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
14
|
-
#[cfg(feature = "strum")]
|
|
15
|
-
use strum_macros::EnumIter;
|
|
16
3
|
|
|
17
4
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
18
5
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
19
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
6
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
20
7
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
21
8
|
pub enum DistanceUnit {
|
|
22
9
|
km,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum ForceUnit {
|
|
21
8
|
GN,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum ForceAreaUnit {
|
|
21
8
|
Nmsq,
|
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
2
|
use crate::quantities::*;
|
|
4
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
5
|
-
use num_traits::identities::Zero;
|
|
6
|
-
use num_traits::{Float, FromPrimitive};
|
|
7
|
-
#[cfg(feature = "pyo3")]
|
|
8
|
-
use pyo3::pyclass;
|
|
9
|
-
#[cfg(feature = "serde")]
|
|
10
|
-
use serde::{Deserialize, Serialize};
|
|
11
|
-
use std::cmp::Ordering;
|
|
12
|
-
use std::fmt;
|
|
13
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
14
|
-
#[cfg(feature = "strum")]
|
|
15
|
-
use strum_macros::EnumIter;
|
|
16
3
|
|
|
17
4
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
18
5
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
19
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
6
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
20
7
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
21
8
|
pub enum ForceDistanceUnit {
|
|
22
9
|
Nm,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum ForcePerDistancePowerFourUnit {
|
|
21
8
|
N_mmhc,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum ForcePerVolumeUnit {
|
|
21
8
|
N_mcb,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum ForceStressUnit {
|
|
21
8
|
Nsq_msq,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum ForceVolumeUnit {
|
|
21
8
|
Nmcb,
|
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
2
|
use crate::Area;
|
|
4
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
5
|
-
use num_traits::identities::Zero;
|
|
6
|
-
use num_traits::{Float, FromPrimitive};
|
|
7
|
-
#[cfg(feature = "pyo3")]
|
|
8
|
-
use pyo3::pyclass;
|
|
9
|
-
#[cfg(feature = "serde")]
|
|
10
|
-
use serde::{Deserialize, Serialize};
|
|
11
|
-
use std::cmp::Ordering;
|
|
12
|
-
use std::fmt;
|
|
13
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
14
|
-
#[cfg(feature = "strum")]
|
|
15
|
-
use strum_macros::EnumIter;
|
|
16
3
|
|
|
17
4
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
18
5
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
19
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
6
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
20
7
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
21
8
|
pub enum InverseAreaUnit {
|
|
22
9
|
_msq,
|
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
2
|
use crate::quantities::*;
|
|
4
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
5
|
-
use num_traits::identities::Zero;
|
|
6
|
-
use num_traits::{Float, FromPrimitive};
|
|
7
|
-
#[cfg(feature = "pyo3")]
|
|
8
|
-
use pyo3::pyclass;
|
|
9
|
-
#[cfg(feature = "serde")]
|
|
10
|
-
use serde::{Deserialize, Serialize};
|
|
11
|
-
use std::cmp::Ordering;
|
|
12
|
-
use std::fmt;
|
|
13
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
14
|
-
#[cfg(feature = "strum")]
|
|
15
|
-
use strum_macros::EnumIter;
|
|
16
3
|
|
|
17
4
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
18
5
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
19
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
6
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
20
7
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
21
8
|
pub enum InverseDistanceUnit {
|
|
22
9
|
_km,
|
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
2
|
use crate::Stress;
|
|
4
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
5
|
-
use num_traits::identities::Zero;
|
|
6
|
-
use num_traits::{Float, FromPrimitive};
|
|
7
|
-
#[cfg(feature = "pyo3")]
|
|
8
|
-
use pyo3::pyclass;
|
|
9
|
-
#[cfg(feature = "serde")]
|
|
10
|
-
use serde::{Deserialize, Serialize};
|
|
11
|
-
use std::cmp::Ordering;
|
|
12
|
-
use std::fmt;
|
|
13
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
14
|
-
#[cfg(feature = "strum")]
|
|
15
|
-
use strum_macros::EnumIter;
|
|
16
3
|
|
|
17
4
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
18
5
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
19
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
6
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
20
7
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
21
8
|
pub enum InverseStressUnit {
|
|
22
9
|
_Pa,
|
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
2
|
use crate::quantities::*;
|
|
4
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
5
|
-
use num_traits::identities::Zero;
|
|
6
|
-
use num_traits::{Float, FromPrimitive};
|
|
7
|
-
#[cfg(feature = "pyo3")]
|
|
8
|
-
use pyo3::pyclass;
|
|
9
|
-
#[cfg(feature = "serde")]
|
|
10
|
-
use serde::{Deserialize, Serialize};
|
|
11
|
-
use std::cmp::Ordering;
|
|
12
|
-
use std::fmt;
|
|
13
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
14
|
-
#[cfg(feature = "strum")]
|
|
15
|
-
use strum_macros::EnumIter;
|
|
16
3
|
|
|
17
4
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
18
5
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
19
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
6
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
20
7
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
21
8
|
pub enum MassUnit {
|
|
22
9
|
mg,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum MassDivTimeSquaredVolumeUnit {
|
|
21
8
|
kg_ssqmq,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum MassPerDistanceUnit {
|
|
21
8
|
kg_m,
|
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
2
|
use crate::PhysicsUnit;
|
|
4
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
5
|
-
use num_traits::identities::Zero;
|
|
6
|
-
use num_traits::{Float, FromPrimitive};
|
|
7
|
-
#[cfg(feature = "pyo3")]
|
|
8
|
-
use pyo3::pyclass;
|
|
9
|
-
#[cfg(feature = "serde")]
|
|
10
|
-
use serde::{Deserialize, Serialize};
|
|
11
|
-
use std::cmp::Ordering;
|
|
12
|
-
use std::fmt;
|
|
13
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
14
|
-
#[cfg(feature = "strum")]
|
|
15
|
-
use strum_macros::EnumIter;
|
|
16
3
|
|
|
17
4
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
18
5
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
19
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
6
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
20
7
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
21
8
|
pub enum RotationalStiffnessUnit {
|
|
22
9
|
Nmm_deg,
|
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
2
|
use crate::PhysicsUnit;
|
|
4
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
5
|
-
use num_traits::identities::Zero;
|
|
6
|
-
use num_traits::{Float, FromPrimitive};
|
|
7
|
-
#[cfg(feature = "pyo3")]
|
|
8
|
-
use pyo3::pyclass;
|
|
9
|
-
#[cfg(feature = "serde")]
|
|
10
|
-
use serde::{Deserialize, Serialize};
|
|
11
|
-
use std::cmp::Ordering;
|
|
12
|
-
use std::fmt;
|
|
13
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
14
|
-
#[cfg(feature = "strum")]
|
|
15
|
-
use strum_macros::EnumIter;
|
|
16
3
|
|
|
17
4
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
18
5
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
19
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
6
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
20
7
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
21
8
|
pub enum StiffnessUnit {
|
|
22
9
|
N_mm,
|
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
2
|
use crate::{Distance, PhysicsUnit, Stress};
|
|
4
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
5
|
-
use num_traits::identities::Zero;
|
|
6
|
-
use num_traits::{Float, FromPrimitive};
|
|
7
|
-
#[cfg(feature = "pyo3")]
|
|
8
|
-
use pyo3::pyclass;
|
|
9
|
-
#[cfg(feature = "serde")]
|
|
10
|
-
use serde::{Deserialize, Serialize};
|
|
11
|
-
use std::cmp::Ordering;
|
|
12
|
-
use std::fmt;
|
|
13
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
14
|
-
#[cfg(feature = "strum")]
|
|
15
|
-
use strum_macros::EnumIter;
|
|
16
3
|
|
|
17
4
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
18
5
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
19
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
6
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
20
7
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
21
8
|
pub enum StrainUnit {
|
|
22
9
|
m_m,
|
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
2
|
use crate::quantities::*;
|
|
4
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
5
|
-
use num_traits::identities::Zero;
|
|
6
|
-
use num_traits::{Float, FromPrimitive};
|
|
7
|
-
#[cfg(feature = "pyo3")]
|
|
8
|
-
use pyo3::pyclass;
|
|
9
|
-
#[cfg(feature = "serde")]
|
|
10
|
-
use serde::{Deserialize, Serialize};
|
|
11
|
-
use std::cmp::Ordering;
|
|
12
|
-
use std::fmt;
|
|
13
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
14
|
-
#[cfg(feature = "strum")]
|
|
15
|
-
use strum_macros::EnumIter;
|
|
16
3
|
|
|
17
4
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
18
5
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
19
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
6
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
20
7
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
21
8
|
pub enum StressUnit {
|
|
22
9
|
Pa,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum StressSquaredUnit {
|
|
21
8
|
Nsq_mmhc,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum TimeUnit {
|
|
21
8
|
ns,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum VelocityUnit {
|
|
21
8
|
km_s,
|
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
2
|
use crate::quantities::*;
|
|
4
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
5
|
-
use num_traits::identities::Zero;
|
|
6
|
-
use num_traits::{Float, FromPrimitive};
|
|
7
|
-
#[cfg(feature = "pyo3")]
|
|
8
|
-
use pyo3::pyclass;
|
|
9
|
-
#[cfg(feature = "serde")]
|
|
10
|
-
use serde::{Deserialize, Serialize};
|
|
11
|
-
use std::cmp::Ordering;
|
|
12
|
-
use std::fmt;
|
|
13
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
14
|
-
#[cfg(feature = "strum")]
|
|
15
|
-
use strum_macros::EnumIter;
|
|
16
3
|
|
|
17
4
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
18
5
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
19
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
6
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
20
7
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
21
8
|
pub enum VelocitySquaredUnit {
|
|
22
9
|
msq_ssq,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum VoltageUnit {
|
|
21
8
|
V,
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
use crate::impl_macros::macros::*;
|
|
2
|
-
use crate::prelude::*;
|
|
3
|
-
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
|
|
4
|
-
use num_traits::identities::Zero;
|
|
5
|
-
use num_traits::{Float, FromPrimitive};
|
|
6
|
-
#[cfg(feature = "pyo3")]
|
|
7
|
-
use pyo3::pyclass;
|
|
8
|
-
#[cfg(feature = "serde")]
|
|
9
|
-
use serde::{Deserialize, Serialize};
|
|
10
|
-
use std::cmp::Ordering;
|
|
11
|
-
use std::fmt;
|
|
12
|
-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
|
13
|
-
#[cfg(feature = "strum")]
|
|
14
|
-
use strum_macros::EnumIter;
|
|
15
2
|
|
|
16
3
|
#[cfg_attr(feature = "strum", derive(EnumIter))]
|
|
17
4
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
18
|
-
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
5
|
+
#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
|
|
19
6
|
#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
|
|
20
7
|
pub enum VolumeUnit {
|
|
21
8
|
kmcb,
|
|
@@ -105,7 +105,28 @@ mod tests {
|
|
|
105
105
|
#[test]
|
|
106
106
|
fn test_optimal_unit() {
|
|
107
107
|
let area = Area::new(0.0001, AreaUnit::msq);
|
|
108
|
-
let optimal_unit = area.optimal_unit().unwrap();
|
|
108
|
+
let optimal_unit = area.optimal_unit(None).unwrap();
|
|
109
|
+
assert_eq!(optimal_unit, AreaUnit::cmsq)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#[cfg(feature = "strum")]
|
|
113
|
+
#[test]
|
|
114
|
+
fn test_optimal_unit_with_selection_strum() {
|
|
115
|
+
let area = Area::new(0.0001, AreaUnit::msq);
|
|
116
|
+
let optimal_unit = area.optimal_unit(Some(vec![AreaUnit::kmsq, AreaUnit::cmsq, AreaUnit::nmsq].into_iter().collect())).unwrap();
|
|
117
|
+
assert_eq!(optimal_unit, AreaUnit::cmsq)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
#[test]
|
|
121
|
+
fn test_optimal_unit_with_selection() {
|
|
122
|
+
let area = Area::new(0.0001, AreaUnit::msq);
|
|
123
|
+
let optimal_unit = area
|
|
124
|
+
.optimal_unit(
|
|
125
|
+
vec![AreaUnit::kmsq, AreaUnit::cmsq, AreaUnit::nmsq]
|
|
126
|
+
.into_iter()
|
|
127
|
+
.collect::<std::collections::HashSet<_>>(),
|
|
128
|
+
)
|
|
129
|
+
.unwrap();
|
|
109
130
|
assert_eq!(optimal_unit, AreaUnit::cmsq)
|
|
110
131
|
}
|
|
111
132
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "unitforge_macros"
|
|
3
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.15"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
authors = ["Dr.Q team <info@askdrq.com>", "Henrik Stromberg <henrik@askdrq.com>"]
|
|
6
6
|
description = "Proc macros for generating units, quantities, and Python bindings in unitforge"
|
|
@@ -244,6 +244,75 @@ fn parse_unit_variants(files: &[String], unit_name: &str) -> Result<Vec<String>,
|
|
|
244
244
|
Err(format!("Enum {unit_name} not found in quantity source files"))
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
+
fn fnv1a32(input: &str) -> u32 {
|
|
248
|
+
const OFFSET_BASIS: u32 = 0x811C9DC5;
|
|
249
|
+
const FNV_PRIME: u32 = 0x01000193;
|
|
250
|
+
|
|
251
|
+
let mut hash = OFFSET_BASIS;
|
|
252
|
+
for byte in input.as_bytes() {
|
|
253
|
+
hash ^= *byte as u32;
|
|
254
|
+
hash = hash.wrapping_mul(FNV_PRIME);
|
|
255
|
+
}
|
|
256
|
+
hash
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
fn stable_non_zero_hash(namespace: &str, name: &str) -> u32 {
|
|
260
|
+
let key = format!("{namespace}:{name}");
|
|
261
|
+
let mut hash = fnv1a32(&key);
|
|
262
|
+
if hash == 0 {
|
|
263
|
+
hash = fnv1a32(&format!("{key}#"));
|
|
264
|
+
if hash == 0 {
|
|
265
|
+
hash = 1;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
hash
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
fn stable_quantity_kind_id(quantity_name: &str) -> u32 {
|
|
272
|
+
stable_non_zero_hash("unitforge.quantity", quantity_name)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
fn stable_unit_variant_id(unit_name: &str, variant_name: &str) -> i32 {
|
|
276
|
+
let hash = stable_non_zero_hash(
|
|
277
|
+
"unitforge.unit_variant",
|
|
278
|
+
&format!("{unit_name}.{variant_name}"),
|
|
279
|
+
);
|
|
280
|
+
(hash & 0x7FFF_FFFF) as i32
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
fn ensure_stable_id_collisions(
|
|
284
|
+
quantity_names: &[String],
|
|
285
|
+
unit_variants_by_name: &HashMap<String, Vec<String>>,
|
|
286
|
+
) -> Result<(), String> {
|
|
287
|
+
let mut quantity_ids: HashMap<u32, String> = HashMap::new();
|
|
288
|
+
for quantity_name in quantity_names {
|
|
289
|
+
let id = stable_quantity_kind_id(quantity_name);
|
|
290
|
+
if let Some(existing) = quantity_ids.insert(id, quantity_name.clone()) {
|
|
291
|
+
if existing != *quantity_name {
|
|
292
|
+
return Err(format!(
|
|
293
|
+
"Quantity kind id collision: '{existing}' and '{quantity_name}' both map to id {id}"
|
|
294
|
+
));
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
for (unit_name, variants) in unit_variants_by_name {
|
|
300
|
+
let mut variant_ids: HashMap<i32, String> = HashMap::new();
|
|
301
|
+
for variant_name in variants {
|
|
302
|
+
let id = stable_unit_variant_id(unit_name, variant_name);
|
|
303
|
+
if let Some(existing) = variant_ids.insert(id, variant_name.clone()) {
|
|
304
|
+
if existing != *variant_name {
|
|
305
|
+
return Err(format!(
|
|
306
|
+
"Unit variant id collision in {unit_name}: '{existing}' and '{variant_name}' both map to id {id}"
|
|
307
|
+
));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
Ok(())
|
|
314
|
+
}
|
|
315
|
+
|
|
247
316
|
fn write_quantity_code(
|
|
248
317
|
template: &str,
|
|
249
318
|
files: &[String],
|
|
@@ -283,6 +352,7 @@ fn write_quantity_code(
|
|
|
283
352
|
let variants = parse_unit_variants(files, &unit_name)?;
|
|
284
353
|
unit_variants_by_name.insert(unit_name, variants);
|
|
285
354
|
}
|
|
355
|
+
ensure_stable_id_collisions(quantity_names, &unit_variants_by_name)?;
|
|
286
356
|
|
|
287
357
|
let mul_macro_re = Regex::new(r"impl_mul!\(\s*(\w+),\s*(\w+),\s*(\w+)\)").unwrap();
|
|
288
358
|
let div_macro_re = Regex::new(r"impl_div!\(\s*(\w+),\s*(\w+),\s*(\w+)\)").unwrap();
|
|
@@ -294,8 +364,8 @@ fn write_quantity_code(
|
|
|
294
364
|
let mul_self_rel_re = Regex::new(r"impl_mul_relation_with_self!\(\s*(\w+),\s*(\w+)\)").unwrap();
|
|
295
365
|
|
|
296
366
|
let mut first = true;
|
|
297
|
-
for
|
|
298
|
-
let quantity_kind_id = (
|
|
367
|
+
for struct_name in quantity_names {
|
|
368
|
+
let quantity_kind_id = stable_quantity_kind_id(struct_name);
|
|
299
369
|
let unit_name = format!("{struct_name}Unit");
|
|
300
370
|
let unit_variant_list = unit_variants_by_name
|
|
301
371
|
.get(&unit_name)
|
|
@@ -371,12 +441,13 @@ fn write_quantity_code(
|
|
|
371
441
|
|
|
372
442
|
let mut variant_to_id_match = String::new();
|
|
373
443
|
let mut id_to_variant_match = String::new();
|
|
374
|
-
for
|
|
444
|
+
for variant_name in unit_variant_list {
|
|
445
|
+
let variant_id = stable_unit_variant_id(&unit_name, variant_name);
|
|
375
446
|
variant_to_id_match += &format!(
|
|
376
|
-
" {struct_name}Unit::{variant_name} => {
|
|
447
|
+
" {struct_name}Unit::{variant_name} => {variant_id},\n"
|
|
377
448
|
);
|
|
378
449
|
id_to_variant_match += &format!(
|
|
379
|
-
" {
|
|
450
|
+
" {variant_id} => Some({struct_name}Unit::{variant_name}),\n"
|
|
380
451
|
);
|
|
381
452
|
}
|
|
382
453
|
unit_variant_id_impls += &format!(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|