siderust-js 0.1.0
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.
- package/.github/workflows/ci.yml +166 -0
- package/.gitmodules +9 -0
- package/CHANGELOG.md +26 -0
- package/LICENSE +661 -0
- package/README.md +138 -0
- package/package.json +12 -0
- package/qtty-js/.github/workflows/ci.yml +151 -0
- package/qtty-js/.gitmodules +3 -0
- package/qtty-js/CHANGELOG.md +31 -0
- package/qtty-js/LICENSE +661 -0
- package/qtty-js/README.md +132 -0
- package/qtty-js/package.json +20 -0
- package/qtty-js/qtty/.github/workflows/ci.yml +155 -0
- package/qtty-js/qtty/CHANGELOG.md +120 -0
- package/qtty-js/qtty/Cargo.lock +1462 -0
- package/qtty-js/qtty/Cargo.toml +12 -0
- package/qtty-js/qtty/LICENSE +661 -0
- package/qtty-js/qtty/README.md +9 -0
- package/qtty-js/qtty/qtty/Cargo.toml +41 -0
- package/qtty-js/qtty/qtty/README.md +8 -0
- package/qtty-js/qtty/qtty/examples/angles.rs +14 -0
- package/qtty-js/qtty/qtty/examples/astronomy.rs +17 -0
- package/qtty-js/qtty/qtty/examples/dimensional_arithmetic.rs +83 -0
- package/qtty-js/qtty/qtty/examples/python_integration.rs +61 -0
- package/qtty-js/qtty/qtty/examples/quickstart.rs +15 -0
- package/qtty-js/qtty/qtty/examples/ratios.rs +12 -0
- package/qtty-js/qtty/qtty/examples/serde_with_unit.rs +234 -0
- package/qtty-js/qtty/qtty/examples/serialization.rs +141 -0
- package/qtty-js/qtty/qtty/examples/serialization_advanced.rs +155 -0
- package/qtty-js/qtty/qtty/src/f32.rs +108 -0
- package/qtty-js/qtty/qtty/src/f64.rs +30 -0
- package/qtty-js/qtty/qtty/src/i128.rs +111 -0
- package/qtty-js/qtty/qtty/src/i16.rs +111 -0
- package/qtty-js/qtty/qtty/src/i32.rs +111 -0
- package/qtty-js/qtty/qtty/src/i64.rs +111 -0
- package/qtty-js/qtty/qtty/src/i8.rs +111 -0
- package/qtty-js/qtty/qtty/src/lib.rs +238 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/src/lib.rs +7 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/src/lib.rs +7 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/src/lib.rs +5 -0
- package/qtty-js/qtty/qtty/tests/integration_tests.rs +529 -0
- package/qtty-js/qtty/qtty/tests/qtty_vec_feature_matrix.rs +58 -0
- package/qtty-js/qtty/qtty-core/Cargo.toml +41 -0
- package/qtty-js/qtty/qtty-core/README.md +8 -0
- package/qtty-js/qtty/qtty-core/examples/diesel_integration.rs +145 -0
- package/qtty-js/qtty/qtty-core/examples/quantity_db_serde.rs +215 -0
- package/qtty-js/qtty/qtty-core/src/dimension.rs +249 -0
- package/qtty-js/qtty/qtty-core/src/feature_diesel.rs +318 -0
- package/qtty-js/qtty/qtty-core/src/feature_pyo3.rs +27 -0
- package/qtty-js/qtty/qtty-core/src/feature_serde.rs +203 -0
- package/qtty-js/qtty/qtty-core/src/feature_tiberius.rs +28 -0
- package/qtty-js/qtty/qtty-core/src/lib.rs +744 -0
- package/qtty-js/qtty/qtty-core/src/macros.rs +93 -0
- package/qtty-js/qtty/qtty-core/src/quantity.rs +810 -0
- package/qtty-js/qtty/qtty-core/src/scalar.rs +1742 -0
- package/qtty-js/qtty/qtty-core/src/unit.rs +332 -0
- package/qtty-js/qtty/qtty-core/src/units/angular.rs +1228 -0
- package/qtty-js/qtty/qtty-core/src/units/area.rs +243 -0
- package/qtty-js/qtty/qtty-core/src/units/frequency.rs +179 -0
- package/qtty-js/qtty/qtty-core/src/units/length.rs +1270 -0
- package/qtty-js/qtty/qtty-core/src/units/mass.rs +488 -0
- package/qtty-js/qtty/qtty-core/src/units/mod.rs +26 -0
- package/qtty-js/qtty/qtty-core/src/units/power.rs +324 -0
- package/qtty-js/qtty/qtty-core/src/units/time.rs +667 -0
- package/qtty-js/qtty/qtty-core/src/units/unitless.rs +212 -0
- package/qtty-js/qtty/qtty-core/src/units/velocity.rs +210 -0
- package/qtty-js/qtty/qtty-core/src/units/volume.rs +269 -0
- package/qtty-js/qtty/qtty-core/tests/core.rs +628 -0
- package/qtty-js/qtty/qtty-core/tests/diesel.rs +461 -0
- package/qtty-js/qtty/qtty-core/tests/integers.rs +632 -0
- package/qtty-js/qtty/qtty-core/tests/no_cross_unit_ops.rs +35 -0
- package/qtty-js/qtty/qtty-core/tests/pyo3.rs +334 -0
- package/qtty-js/qtty/qtty-core/tests/quantity_f32.rs +276 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_decimal.rs +258 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_f32.rs +286 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_f64_real.rs +287 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_rational.rs +260 -0
- package/qtty-js/qtty/qtty-core/tests/serde.rs +256 -0
- package/qtty-js/qtty/qtty-core/tests/tiberius.rs +208 -0
- package/qtty-js/qtty/qtty-derive/Cargo.toml +23 -0
- package/qtty-js/qtty/qtty-derive/README.md +8 -0
- package/qtty-js/qtty/qtty-derive/src/lib.rs +340 -0
- package/qtty-js/qtty/qtty-ffi/ARCHITECTURE.md +3 -0
- package/qtty-js/qtty/qtty-ffi/Cargo.toml +31 -0
- package/qtty-js/qtty/qtty-ffi/README.md +9 -0
- package/qtty-js/qtty/qtty-ffi/build.rs +326 -0
- package/qtty-js/qtty/qtty-ffi/cbindgen.toml +105 -0
- package/qtty-js/qtty/qtty-ffi/include/qtty_ffi.h +1126 -0
- package/qtty-js/qtty/qtty-ffi/src/ffi.rs +1251 -0
- package/qtty-js/qtty/qtty-ffi/src/ffi_serde.rs +294 -0
- package/qtty-js/qtty/qtty-ffi/src/helpers.rs +310 -0
- package/qtty-js/qtty/qtty-ffi/src/lib.rs +229 -0
- package/qtty-js/qtty/qtty-ffi/src/macros.rs +121 -0
- package/qtty-js/qtty/qtty-ffi/src/registry.rs +274 -0
- package/qtty-js/qtty/qtty-ffi/src/types.rs +620 -0
- package/qtty-js/qtty/qtty-ffi/tests/integration_tests.rs +842 -0
- package/qtty-js/qtty/qtty-ffi/units.csv +156 -0
- package/qtty-js/qtty/qtty-ffi/units.csv.md +3 -0
- package/qtty-js/qtty-node/.prettierignore +6 -0
- package/qtty-js/qtty-node/.prettierrc.json +6 -0
- package/qtty-js/qtty-node/README.md +250 -0
- package/qtty-js/qtty-node/c8.config.json +11 -0
- package/qtty-js/qtty-node/eslint.config.js +31 -0
- package/qtty-js/qtty-node/examples/arithmetic.mjs +64 -0
- package/qtty-js/qtty-node/examples/astronomy.mjs +90 -0
- package/qtty-js/qtty-node/examples/quickstart.mjs +36 -0
- package/qtty-js/qtty-node/examples/serialization.mjs +125 -0
- package/qtty-js/qtty-node/examples/unit_factories.mjs +74 -0
- package/qtty-js/qtty-node/index.d.ts +219 -0
- package/qtty-js/qtty-node/index.js +323 -0
- package/qtty-js/qtty-node/lib/DerivedQuantity.js +122 -0
- package/qtty-js/qtty-node/lib/Quantity.js +151 -0
- package/qtty-js/qtty-node/lib/backend.js +25 -0
- package/qtty-js/qtty-node/native.cjs +306 -0
- package/qtty-js/qtty-node/package-lock.json +3223 -0
- package/qtty-js/qtty-node/package.json +70 -0
- package/qtty-js/qtty-node/units.d.ts +299 -0
- package/qtty-js/qtty-node/units.js +210 -0
- package/qtty-js/qtty-web/Cargo.lock +767 -0
- package/qtty-js/qtty-web/Cargo.toml +21 -0
- package/qtty-js/qtty-web/index.d.ts +140 -0
- package/qtty-js/qtty-web/index.js +20 -0
- package/qtty-js/qtty-web/lib/DerivedQuantity.js +58 -0
- package/qtty-js/qtty-web/lib/Quantity.js +75 -0
- package/qtty-js/qtty-web/lib/backend.js +80 -0
- package/qtty-js/qtty-web/package.json +45 -0
- package/qtty-js/qtty-web/src/lib.rs +111 -0
- package/qtty-js/scripts/ci.sh +73 -0
- package/scripts/ci.sh +123 -0
- package/siderust-core/Cargo.lock +787 -0
- package/siderust-core/Cargo.toml +18 -0
- package/siderust-core/DEDUPLICATION.md +124 -0
- package/siderust-core/src/body.rs +120 -0
- package/siderust-core/src/events.rs +184 -0
- package/siderust-core/src/lib.rs +20 -0
- package/siderust-core/src/observer.rs +55 -0
- package/siderust-core/src/position.rs +213 -0
- package/siderust-node/.prettierignore +7 -0
- package/siderust-node/.prettierrc.json +6 -0
- package/siderust-node/Cargo.lock +906 -0
- package/siderust-node/Cargo.toml +29 -0
- package/siderust-node/README.md +109 -0
- package/siderust-node/__test__/index.test.mjs +248 -0
- package/siderust-node/build.rs +5 -0
- package/siderust-node/c8.config.json +3 -0
- package/siderust-node/eslint.config.js +31 -0
- package/siderust-node/examples/01_basic_coordinates.mjs +24 -0
- package/siderust-node/examples/02_coordinate_transformations.mjs +25 -0
- package/siderust-node/examples/03_all_frames_conversions.mjs +26 -0
- package/siderust-node/examples/04_all_center_conversions.mjs +24 -0
- package/siderust-node/examples/05_target_tracking.mjs +22 -0
- package/siderust-node/examples/06_night_events.mjs +18 -0
- package/siderust-node/examples/07_moon_properties.mjs +21 -0
- package/siderust-node/examples/08_solar_system.mjs +19 -0
- package/siderust-node/examples/09_star_observability.mjs +22 -0
- package/siderust-node/examples/10_time_periods.mjs +9 -0
- package/siderust-node/examples/11_serialization.mjs +31 -0
- package/siderust-node/examples/12_runtime_ephemeris.mjs +27 -0
- package/siderust-node/examples/13_coordinate_operations.mjs +20 -0
- package/siderust-node/index.d.ts +623 -0
- package/siderust-node/index.js +79 -0
- package/siderust-node/lib/Observer.js +112 -0
- package/siderust-node/lib/Star.js +118 -0
- package/siderust-node/lib/backend.js +63 -0
- package/siderust-node/lib/wrappers.js +566 -0
- package/siderust-node/main.js +20 -0
- package/siderust-node/native.cjs +360 -0
- package/siderust-node/package-lock.json +3261 -0
- package/siderust-node/package.json +71 -0
- package/siderust-node/src/body.rs +74 -0
- package/siderust-node/src/coordinates.rs +372 -0
- package/siderust-node/src/ephemeris.rs +462 -0
- package/siderust-node/src/events.rs +577 -0
- package/siderust-node/src/lib.rs +43 -0
- package/siderust-node/src/observer.rs +132 -0
- package/siderust-node/src/phase.rs +218 -0
- package/siderust-node/src/position.rs +292 -0
- package/siderust-node/src/star.rs +200 -0
- package/siderust-web/Cargo.lock +855 -0
- package/siderust-web/Cargo.toml +34 -0
- package/siderust-web/README.md +100 -0
- package/siderust-web/__test__/index.test.mjs +118 -0
- package/siderust-web/examples/github-pages/README.md +31 -0
- package/siderust-web/examples/github-pages/index.html +135 -0
- package/siderust-web/index.d.ts +311 -0
- package/siderust-web/index.js +66 -0
- package/siderust-web/lib/Observer.js +103 -0
- package/siderust-web/lib/Star.js +116 -0
- package/siderust-web/lib/backend.js +400 -0
- package/siderust-web/lib/wrappers.js +512 -0
- package/siderust-web/package.json +55 -0
- package/siderust-web/src/body.rs +69 -0
- package/siderust-web/src/coordinates.rs +302 -0
- package/siderust-web/src/ephemeris.rs +456 -0
- package/siderust-web/src/events.rs +520 -0
- package/siderust-web/src/lib.rs +51 -0
- package/siderust-web/src/observer.rs +117 -0
- package/siderust-web/src/phase.rs +190 -0
- package/siderust-web/src/position.rs +291 -0
- package/siderust-web/src/star.rs +178 -0
- package/tempoch-js/.github/workflows/ci.yml +142 -0
- package/tempoch-js/.gitmodules +3 -0
- package/tempoch-js/CHANGELOG.md +25 -0
- package/tempoch-js/LICENSE +661 -0
- package/tempoch-js/README.md +126 -0
- package/tempoch-js/package.json +20 -0
- package/tempoch-js/scripts/ci.sh +73 -0
- package/tempoch-js/tempoch/.github/workflows/ci.yml +113 -0
- package/tempoch-js/tempoch/CHANGELOG.md +82 -0
- package/tempoch-js/tempoch/Cargo.lock +947 -0
- package/tempoch-js/tempoch/Cargo.toml +3 -0
- package/tempoch-js/tempoch/LICENSE +661 -0
- package/tempoch-js/tempoch/README.md +76 -0
- package/tempoch-js/tempoch/tempoch/Cargo.toml +27 -0
- package/tempoch-js/tempoch/tempoch/examples/periods.rs +45 -0
- package/tempoch-js/tempoch/tempoch/examples/quickstart.rs +13 -0
- package/tempoch-js/tempoch/tempoch/src/lib.rs +49 -0
- package/tempoch-js/tempoch/tempoch/tests/integration.rs +57 -0
- package/tempoch-js/tempoch/tempoch-core/Cargo.toml +24 -0
- package/tempoch-js/tempoch/tempoch-core/src/delta_t.rs +345 -0
- package/tempoch-js/tempoch/tempoch-core/src/instant.rs +811 -0
- package/tempoch-js/tempoch/tempoch-core/src/julian_date_ext.rs +142 -0
- package/tempoch-js/tempoch/tempoch-core/src/lib.rs +81 -0
- package/tempoch-js/tempoch/tempoch-core/src/period.rs +1168 -0
- package/tempoch-js/tempoch/tempoch-core/src/scales.rs +779 -0
- package/tempoch-js/tempoch/tempoch-ffi/Cargo.lock +889 -0
- package/tempoch-js/tempoch/tempoch-ffi/Cargo.toml +26 -0
- package/tempoch-js/tempoch/tempoch-ffi/build.rs +24 -0
- package/tempoch-js/tempoch/tempoch-ffi/cbindgen.toml +30 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/error.rs +19 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/lib.rs +82 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/period.rs +101 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/time.rs +711 -0
- package/tempoch-js/tempoch/tempoch-ffi/tests/ffi.rs +265 -0
- package/tempoch-js/tempoch-node/.prettierignore +6 -0
- package/tempoch-js/tempoch-node/.prettierrc.json +6 -0
- package/tempoch-js/tempoch-node/Cargo.lock +496 -0
- package/tempoch-js/tempoch-node/Cargo.toml +29 -0
- package/tempoch-js/tempoch-node/README.md +265 -0
- package/tempoch-js/tempoch-node/__test__/index.test.mjs +598 -0
- package/tempoch-js/tempoch-node/build.rs +5 -0
- package/tempoch-js/tempoch-node/c8.config.json +3 -0
- package/tempoch-js/tempoch-node/eslint.config.js +31 -0
- package/tempoch-js/tempoch-node/examples/periods.mjs +79 -0
- package/tempoch-js/tempoch-node/examples/quickstart.mjs +71 -0
- package/tempoch-js/tempoch-node/examples/timescales.mjs +92 -0
- package/tempoch-js/tempoch-node/index.d.ts +280 -0
- package/tempoch-js/tempoch-node/index.js +32 -0
- package/tempoch-js/tempoch-node/lib/JulianDate.js +176 -0
- package/tempoch-js/tempoch-node/lib/ModifiedJulianDate.js +156 -0
- package/tempoch-js/tempoch-node/lib/Period.js +133 -0
- package/tempoch-js/tempoch-node/lib/backend.js +38 -0
- package/tempoch-js/tempoch-node/lib/qttyCompat.js +92 -0
- package/tempoch-js/tempoch-node/native.cjs +317 -0
- package/tempoch-js/tempoch-node/package-lock.json +3223 -0
- package/tempoch-js/tempoch-node/package.json +56 -0
- package/tempoch-js/tempoch-node/src/lib.rs +573 -0
- package/tempoch-js/tempoch-web/Cargo.toml +23 -0
- package/tempoch-js/tempoch-web/index.d.ts +95 -0
- package/tempoch-js/tempoch-web/index.js +27 -0
- package/tempoch-js/tempoch-web/lib/JulianDate.js +170 -0
- package/tempoch-js/tempoch-web/lib/ModifiedJulianDate.js +145 -0
- package/tempoch-js/tempoch-web/lib/Period.js +121 -0
- package/tempoch-js/tempoch-web/lib/backend.js +118 -0
- package/tempoch-js/tempoch-web/package.json +46 -0
- package/tempoch-js/tempoch-web/src/lib.rs +184 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
//! Advanced serialization examples showing edge cases and best practices.
|
|
2
|
+
//!
|
|
3
|
+
//! Run with: cargo run --example serialization_advanced --features serde
|
|
4
|
+
|
|
5
|
+
#[cfg(feature = "serde")]
|
|
6
|
+
fn main() {
|
|
7
|
+
use qtty::{Kilometers, Meters, Seconds};
|
|
8
|
+
use serde::{Deserialize, Serialize};
|
|
9
|
+
use serde_json;
|
|
10
|
+
|
|
11
|
+
println!("=== Advanced Serialization Examples ===\n");
|
|
12
|
+
|
|
13
|
+
// Example 1: Handling zero and special values
|
|
14
|
+
println!("1. Special Values:");
|
|
15
|
+
let zero = Meters::new(0.0);
|
|
16
|
+
let json = serde_json::to_string(&zero).unwrap();
|
|
17
|
+
println!(" Zero: {} → {}", zero, json);
|
|
18
|
+
|
|
19
|
+
let negative = Meters::new(-42.5);
|
|
20
|
+
let json = serde_json::to_string(&negative).unwrap();
|
|
21
|
+
println!(" Negative: {} → {}", negative, json);
|
|
22
|
+
|
|
23
|
+
let large = Meters::new(1.23e15);
|
|
24
|
+
let json = serde_json::to_string(&large).unwrap();
|
|
25
|
+
println!(" Large number: {} → {}", large, json);
|
|
26
|
+
println!();
|
|
27
|
+
|
|
28
|
+
// Example 2: Nested structures
|
|
29
|
+
println!("2. Nested Structures:");
|
|
30
|
+
#[derive(Serialize, Deserialize, Debug)]
|
|
31
|
+
struct Location {
|
|
32
|
+
name: String,
|
|
33
|
+
coordinates: Coordinates,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
#[derive(Serialize, Deserialize, Debug)]
|
|
37
|
+
struct Coordinates {
|
|
38
|
+
x: Meters,
|
|
39
|
+
y: Meters,
|
|
40
|
+
z: Meters,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let location = Location {
|
|
44
|
+
name: "Mount Everest".to_string(),
|
|
45
|
+
coordinates: Coordinates {
|
|
46
|
+
x: Meters::new(86.925278),
|
|
47
|
+
y: Meters::new(27.988056),
|
|
48
|
+
z: Meters::new(8848.86),
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
let json = serde_json::to_string_pretty(&location).unwrap();
|
|
53
|
+
println!("{}", json);
|
|
54
|
+
|
|
55
|
+
let restored: Location = serde_json::from_str(&json).unwrap();
|
|
56
|
+
println!(" Restored name: {}", restored.name);
|
|
57
|
+
println!();
|
|
58
|
+
|
|
59
|
+
// Example 3: Option types
|
|
60
|
+
println!("3. Optional Quantities:");
|
|
61
|
+
#[derive(Serialize, Deserialize, Debug)]
|
|
62
|
+
struct Measurement {
|
|
63
|
+
required: Meters,
|
|
64
|
+
optional: Option<Meters>,
|
|
65
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
66
|
+
skipped_if_none: Option<Seconds>,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let with_value = Measurement {
|
|
70
|
+
required: Meters::new(100.0),
|
|
71
|
+
optional: Some(Meters::new(50.0)),
|
|
72
|
+
skipped_if_none: Some(Seconds::new(10.0)),
|
|
73
|
+
};
|
|
74
|
+
println!(
|
|
75
|
+
" With values: {}",
|
|
76
|
+
serde_json::to_string_pretty(&with_value).unwrap()
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
let without_value = Measurement {
|
|
80
|
+
required: Meters::new(100.0),
|
|
81
|
+
optional: None,
|
|
82
|
+
skipped_if_none: None,
|
|
83
|
+
};
|
|
84
|
+
println!(
|
|
85
|
+
" Without optional: {}",
|
|
86
|
+
serde_json::to_string_pretty(&without_value).unwrap()
|
|
87
|
+
);
|
|
88
|
+
println!();
|
|
89
|
+
|
|
90
|
+
// Example 4: Unit conversion awareness
|
|
91
|
+
println!("4. Unit Conversion During Serialization:");
|
|
92
|
+
println!(" ⚠️ WARNING: Always convert to base units before serializing!");
|
|
93
|
+
|
|
94
|
+
let distance_km = Kilometers::new(5.0);
|
|
95
|
+
let distance_m = distance_km.to::<qtty::Meter>();
|
|
96
|
+
|
|
97
|
+
let json_km = serde_json::to_string(&distance_km).unwrap();
|
|
98
|
+
let json_m = serde_json::to_string(&distance_m).unwrap();
|
|
99
|
+
|
|
100
|
+
println!(" 5 km serialized directly: {}", json_km);
|
|
101
|
+
println!(" 5 km converted to meters: {}", json_m);
|
|
102
|
+
println!(" Note: Both serialize the same value, but semantics differ!");
|
|
103
|
+
println!();
|
|
104
|
+
|
|
105
|
+
// Example 5: Error handling
|
|
106
|
+
println!("5. Error Handling:");
|
|
107
|
+
|
|
108
|
+
// Invalid JSON
|
|
109
|
+
let invalid_json = "not_a_number";
|
|
110
|
+
match serde_json::from_str::<Meters>(invalid_json) {
|
|
111
|
+
Ok(_) => println!(" Unexpected success"),
|
|
112
|
+
Err(e) => println!(" Expected error: {}", e),
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Empty string
|
|
116
|
+
let empty = "";
|
|
117
|
+
match serde_json::from_str::<Meters>(empty) {
|
|
118
|
+
Ok(_) => println!(" Unexpected success"),
|
|
119
|
+
Err(e) => println!(" Expected error: {}", e),
|
|
120
|
+
}
|
|
121
|
+
println!();
|
|
122
|
+
|
|
123
|
+
// Example 6: Compact vs Pretty printing
|
|
124
|
+
println!("6. Compact vs Pretty Printing:");
|
|
125
|
+
#[derive(Serialize, Deserialize)]
|
|
126
|
+
struct Data {
|
|
127
|
+
distances: Vec<Meters>,
|
|
128
|
+
times: Vec<Seconds>,
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let data = Data {
|
|
132
|
+
distances: vec![Meters::new(1.0), Meters::new(2.0), Meters::new(3.0)],
|
|
133
|
+
times: vec![Seconds::new(0.1), Seconds::new(0.2), Seconds::new(0.3)],
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
let compact = serde_json::to_string(&data).unwrap();
|
|
137
|
+
println!(" Compact: {}", compact);
|
|
138
|
+
|
|
139
|
+
let pretty = serde_json::to_string_pretty(&data).unwrap();
|
|
140
|
+
println!(" Pretty:\n{}", pretty);
|
|
141
|
+
println!();
|
|
142
|
+
|
|
143
|
+
println!("=== Best Practices ===");
|
|
144
|
+
println!("✓ Always convert to base SI units before serializing");
|
|
145
|
+
println!("✓ Document the expected unit in your API documentation");
|
|
146
|
+
println!("✓ Validate deserialized values are in expected range");
|
|
147
|
+
println!("✓ Consider creating custom serializers for complex scenarios");
|
|
148
|
+
println!("✓ Use Option<Quantity<U>> for optional measurements");
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
#[cfg(not(feature = "serde"))]
|
|
152
|
+
fn main() {
|
|
153
|
+
println!("This example requires the 'serde' feature.");
|
|
154
|
+
println!("Run with: cargo run --example serialization_advanced --features serde");
|
|
155
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
//! Re-exports of quantity types specialized to `f32` scalar.
|
|
2
|
+
//!
|
|
3
|
+
//! This module provides type aliases for all unit types using `f32` as the
|
|
4
|
+
//! underlying scalar type. Use this when memory efficiency is more important
|
|
5
|
+
//! than precision.
|
|
6
|
+
//!
|
|
7
|
+
//! # Example
|
|
8
|
+
//!
|
|
9
|
+
//! ```rust
|
|
10
|
+
//! use qtty::f32::{Degrees, Meters, Seconds};
|
|
11
|
+
//!
|
|
12
|
+
//! let angle: Degrees = Degrees::new(90.0_f32);
|
|
13
|
+
//! let distance: Meters = Meters::new(100.0_f32);
|
|
14
|
+
//! let time: Seconds = Seconds::new(10.0_f32);
|
|
15
|
+
//! ```
|
|
16
|
+
|
|
17
|
+
use crate::Quantity;
|
|
18
|
+
|
|
19
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
20
|
+
// Angular units (f32)
|
|
21
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
/// Degrees with `f32` scalar.
|
|
24
|
+
pub type Degrees = Quantity<crate::angular::Degree, f32>;
|
|
25
|
+
/// Radians with `f32` scalar.
|
|
26
|
+
pub type Radians = Quantity<crate::angular::Radian, f32>;
|
|
27
|
+
/// Arcminutes with `f32` scalar.
|
|
28
|
+
pub type Arcminutes = Quantity<crate::angular::Arcminute, f32>;
|
|
29
|
+
/// Arcseconds with `f32` scalar.
|
|
30
|
+
pub type Arcseconds = Quantity<crate::angular::Arcsecond, f32>;
|
|
31
|
+
/// Milliradians with `f32` scalar.
|
|
32
|
+
pub type Milliradians = Quantity<crate::angular::Milliradian, f32>;
|
|
33
|
+
/// Milliarcseconds with `f32` scalar.
|
|
34
|
+
pub type MilliArcseconds = Quantity<crate::angular::MilliArcsecond, f32>;
|
|
35
|
+
/// Microarcseconds with `f32` scalar.
|
|
36
|
+
pub type MicroArcseconds = Quantity<crate::angular::MicroArcsecond, f32>;
|
|
37
|
+
/// Gradians with `f32` scalar.
|
|
38
|
+
pub type Gradians = Quantity<crate::angular::Gradian, f32>;
|
|
39
|
+
/// Turns with `f32` scalar.
|
|
40
|
+
pub type Turns = Quantity<crate::angular::Turn, f32>;
|
|
41
|
+
/// Hour angles with `f32` scalar.
|
|
42
|
+
pub type HourAngles = Quantity<crate::angular::HourAngle, f32>;
|
|
43
|
+
|
|
44
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
45
|
+
// Length units (f32)
|
|
46
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
47
|
+
|
|
48
|
+
/// Meters with `f32` scalar.
|
|
49
|
+
pub type Meters = Quantity<crate::length::Meter, f32>;
|
|
50
|
+
/// Kilometers with `f32` scalar.
|
|
51
|
+
pub type Kilometers = Quantity<crate::length::Kilometer, f32>;
|
|
52
|
+
/// Centimeters with `f32` scalar.
|
|
53
|
+
pub type Centimeters = Quantity<crate::length::Centimeter, f32>;
|
|
54
|
+
/// Millimeters with `f32` scalar.
|
|
55
|
+
pub type Millimeters = Quantity<crate::length::Millimeter, f32>;
|
|
56
|
+
/// Micrometers with `f32` scalar.
|
|
57
|
+
pub type Micrometers = Quantity<crate::length::Micrometer, f32>;
|
|
58
|
+
/// Nanometers with `f32` scalar.
|
|
59
|
+
pub type Nanometers = Quantity<crate::length::Nanometer, f32>;
|
|
60
|
+
/// Astronomical units with `f32` scalar.
|
|
61
|
+
pub type AstronomicalUnits = Quantity<crate::length::AstronomicalUnit, f32>;
|
|
62
|
+
/// Light years with `f32` scalar.
|
|
63
|
+
pub type LightYears = Quantity<crate::length::LightYear, f32>;
|
|
64
|
+
/// Parsecs with `f32` scalar.
|
|
65
|
+
pub type Parsecs = Quantity<crate::length::Parsec, f32>;
|
|
66
|
+
|
|
67
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
68
|
+
// Time units (f32)
|
|
69
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
70
|
+
|
|
71
|
+
/// Seconds with `f32` scalar.
|
|
72
|
+
pub type Seconds = Quantity<crate::time::Second, f32>;
|
|
73
|
+
/// Milliseconds with `f32` scalar.
|
|
74
|
+
pub type Milliseconds = Quantity<crate::time::Millisecond, f32>;
|
|
75
|
+
/// Microseconds with `f32` scalar.
|
|
76
|
+
pub type Microseconds = Quantity<crate::time::Microsecond, f32>;
|
|
77
|
+
/// Nanoseconds with `f32` scalar.
|
|
78
|
+
pub type Nanoseconds = Quantity<crate::time::Nanosecond, f32>;
|
|
79
|
+
/// Minutes with `f32` scalar.
|
|
80
|
+
pub type Minutes = Quantity<crate::time::Minute, f32>;
|
|
81
|
+
/// Hours with `f32` scalar.
|
|
82
|
+
pub type Hours = Quantity<crate::time::Hour, f32>;
|
|
83
|
+
/// Days with `f32` scalar.
|
|
84
|
+
pub type Days = Quantity<crate::time::Day, f32>;
|
|
85
|
+
/// Years with `f32` scalar.
|
|
86
|
+
pub type Years = Quantity<crate::time::Year, f32>;
|
|
87
|
+
|
|
88
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
89
|
+
// Mass units (f32)
|
|
90
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
91
|
+
|
|
92
|
+
/// Grams with `f32` scalar.
|
|
93
|
+
pub type Grams = Quantity<crate::mass::Gram, f32>;
|
|
94
|
+
/// Kilograms with `f32` scalar.
|
|
95
|
+
pub type Kilograms = Quantity<crate::mass::Kilogram, f32>;
|
|
96
|
+
/// Solar masses with `f32` scalar.
|
|
97
|
+
pub type SolarMasses = Quantity<crate::mass::SolarMass, f32>;
|
|
98
|
+
|
|
99
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
100
|
+
// Power units (f32)
|
|
101
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
/// Watts with `f32` scalar.
|
|
104
|
+
pub type Watts = Quantity<crate::power::Watt, f32>;
|
|
105
|
+
/// Kilowatts with `f32` scalar.
|
|
106
|
+
pub type Kilowatts = Quantity<crate::power::Kilowatt, f32>;
|
|
107
|
+
/// Solar luminosities with `f32` scalar.
|
|
108
|
+
pub type SolarLuminosities = Quantity<crate::power::SolarLuminosity, f32>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//! Re-exports of quantity types specialized to `f64` scalar (default).
|
|
2
|
+
//!
|
|
3
|
+
//! This module provides type aliases for all unit types using `f64` as the
|
|
4
|
+
//! underlying scalar type. These are identical to the types exported at the
|
|
5
|
+
//! crate root, but are provided for symmetry with the [`crate::f32`] module.
|
|
6
|
+
//!
|
|
7
|
+
//! # Example
|
|
8
|
+
//!
|
|
9
|
+
//! ```rust
|
|
10
|
+
//! use qtty::f64::{Degrees, Meters, Seconds};
|
|
11
|
+
//!
|
|
12
|
+
//! let angle: Degrees = Degrees::new(90.0);
|
|
13
|
+
//! let distance: Meters = Meters::new(100.0);
|
|
14
|
+
//! let time: Seconds = Seconds::new(10.0);
|
|
15
|
+
//! ```
|
|
16
|
+
|
|
17
|
+
// Re-export the default (f64) types from qtty-core
|
|
18
|
+
pub use crate::angular::{
|
|
19
|
+
Arcminutes, Arcseconds, Degrees, Gradians, HourAngles, MicroArcseconds, MilliArcseconds,
|
|
20
|
+
Milliradians, Radians, Turns,
|
|
21
|
+
};
|
|
22
|
+
pub use crate::length::{
|
|
23
|
+
AstronomicalUnits, Centimeters, Kilometers, LightYears, Meters, Micrometers, Millimeters,
|
|
24
|
+
Nanometers, Parsecs,
|
|
25
|
+
};
|
|
26
|
+
pub use crate::mass::{Grams, Kilograms, SolarMasses};
|
|
27
|
+
pub use crate::power::{Kilowatts, SolarLuminosities, Watts};
|
|
28
|
+
pub use crate::time::{
|
|
29
|
+
Days, Hours, Microseconds, Milliseconds, Minutes, Nanoseconds, Seconds, Years,
|
|
30
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
//! Re-exports of quantity types specialized to `i128` scalar.
|
|
2
|
+
//!
|
|
3
|
+
//! This module provides type aliases for all unit types using `i128` as the
|
|
4
|
+
//! underlying scalar type. Integer quantities provide compile-time unit safety
|
|
5
|
+
//! for discrete values (counters, pixel coordinates, ADC readings, etc.).
|
|
6
|
+
//!
|
|
7
|
+
//! Integer quantities support basic arithmetic but **not** unit conversion via
|
|
8
|
+
//! [`to()`](crate::Quantity::to). Use [`to_lossy()`](crate::Quantity::to_lossy)
|
|
9
|
+
//! for lossy (truncating) conversion between units.
|
|
10
|
+
//!
|
|
11
|
+
//! # Example
|
|
12
|
+
//!
|
|
13
|
+
//! ```rust
|
|
14
|
+
//! use qtty::i128::{Meters, Seconds};
|
|
15
|
+
//!
|
|
16
|
+
//! let distance: Meters = Meters::new(1500);
|
|
17
|
+
//! let time: Seconds = Seconds::new(10);
|
|
18
|
+
//! ```
|
|
19
|
+
|
|
20
|
+
use crate::Quantity;
|
|
21
|
+
|
|
22
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
23
|
+
// Angular units (i128)
|
|
24
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
/// Degrees with `i128` scalar.
|
|
27
|
+
pub type Degrees = Quantity<crate::angular::Degree, i128>;
|
|
28
|
+
/// Radians with `i128` scalar.
|
|
29
|
+
pub type Radians = Quantity<crate::angular::Radian, i128>;
|
|
30
|
+
/// Arcminutes with `i128` scalar.
|
|
31
|
+
pub type Arcminutes = Quantity<crate::angular::Arcminute, i128>;
|
|
32
|
+
/// Arcseconds with `i128` scalar.
|
|
33
|
+
pub type Arcseconds = Quantity<crate::angular::Arcsecond, i128>;
|
|
34
|
+
/// Milliradians with `i128` scalar.
|
|
35
|
+
pub type Milliradians = Quantity<crate::angular::Milliradian, i128>;
|
|
36
|
+
/// Milliarcseconds with `i128` scalar.
|
|
37
|
+
pub type MilliArcseconds = Quantity<crate::angular::MilliArcsecond, i128>;
|
|
38
|
+
/// Microarcseconds with `i128` scalar.
|
|
39
|
+
pub type MicroArcseconds = Quantity<crate::angular::MicroArcsecond, i128>;
|
|
40
|
+
/// Gradians with `i128` scalar.
|
|
41
|
+
pub type Gradians = Quantity<crate::angular::Gradian, i128>;
|
|
42
|
+
/// Turns with `i128` scalar.
|
|
43
|
+
pub type Turns = Quantity<crate::angular::Turn, i128>;
|
|
44
|
+
/// Hour angles with `i128` scalar.
|
|
45
|
+
pub type HourAngles = Quantity<crate::angular::HourAngle, i128>;
|
|
46
|
+
|
|
47
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
48
|
+
// Length units (i128)
|
|
49
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
50
|
+
|
|
51
|
+
/// Meters with `i128` scalar.
|
|
52
|
+
pub type Meters = Quantity<crate::length::Meter, i128>;
|
|
53
|
+
/// Kilometers with `i128` scalar.
|
|
54
|
+
pub type Kilometers = Quantity<crate::length::Kilometer, i128>;
|
|
55
|
+
/// Centimeters with `i128` scalar.
|
|
56
|
+
pub type Centimeters = Quantity<crate::length::Centimeter, i128>;
|
|
57
|
+
/// Millimeters with `i128` scalar.
|
|
58
|
+
pub type Millimeters = Quantity<crate::length::Millimeter, i128>;
|
|
59
|
+
/// Micrometers with `i128` scalar.
|
|
60
|
+
pub type Micrometers = Quantity<crate::length::Micrometer, i128>;
|
|
61
|
+
/// Nanometers with `i128` scalar.
|
|
62
|
+
pub type Nanometers = Quantity<crate::length::Nanometer, i128>;
|
|
63
|
+
/// Astronomical units with `i128` scalar.
|
|
64
|
+
pub type AstronomicalUnits = Quantity<crate::length::AstronomicalUnit, i128>;
|
|
65
|
+
/// Light years with `i128` scalar.
|
|
66
|
+
pub type LightYears = Quantity<crate::length::LightYear, i128>;
|
|
67
|
+
/// Parsecs with `i128` scalar.
|
|
68
|
+
pub type Parsecs = Quantity<crate::length::Parsec, i128>;
|
|
69
|
+
|
|
70
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
71
|
+
// Time units (i128)
|
|
72
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
/// Seconds with `i128` scalar.
|
|
75
|
+
pub type Seconds = Quantity<crate::time::Second, i128>;
|
|
76
|
+
/// Milliseconds with `i128` scalar.
|
|
77
|
+
pub type Milliseconds = Quantity<crate::time::Millisecond, i128>;
|
|
78
|
+
/// Microseconds with `i128` scalar.
|
|
79
|
+
pub type Microseconds = Quantity<crate::time::Microsecond, i128>;
|
|
80
|
+
/// Nanoseconds with `i128` scalar.
|
|
81
|
+
pub type Nanoseconds = Quantity<crate::time::Nanosecond, i128>;
|
|
82
|
+
/// Minutes with `i128` scalar.
|
|
83
|
+
pub type Minutes = Quantity<crate::time::Minute, i128>;
|
|
84
|
+
/// Hours with `i128` scalar.
|
|
85
|
+
pub type Hours = Quantity<crate::time::Hour, i128>;
|
|
86
|
+
/// Days with `i128` scalar.
|
|
87
|
+
pub type Days = Quantity<crate::time::Day, i128>;
|
|
88
|
+
/// Years with `i128` scalar.
|
|
89
|
+
pub type Years = Quantity<crate::time::Year, i128>;
|
|
90
|
+
|
|
91
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
92
|
+
// Mass units (i128)
|
|
93
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
94
|
+
|
|
95
|
+
/// Grams with `i128` scalar.
|
|
96
|
+
pub type Grams = Quantity<crate::mass::Gram, i128>;
|
|
97
|
+
/// Kilograms with `i128` scalar.
|
|
98
|
+
pub type Kilograms = Quantity<crate::mass::Kilogram, i128>;
|
|
99
|
+
/// Solar masses with `i128` scalar.
|
|
100
|
+
pub type SolarMasses = Quantity<crate::mass::SolarMass, i128>;
|
|
101
|
+
|
|
102
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
103
|
+
// Power units (i128)
|
|
104
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
105
|
+
|
|
106
|
+
/// Watts with `i128` scalar.
|
|
107
|
+
pub type Watts = Quantity<crate::power::Watt, i128>;
|
|
108
|
+
/// Kilowatts with `i128` scalar.
|
|
109
|
+
pub type Kilowatts = Quantity<crate::power::Kilowatt, i128>;
|
|
110
|
+
/// Solar luminosities with `i128` scalar.
|
|
111
|
+
pub type SolarLuminosities = Quantity<crate::power::SolarLuminosity, i128>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
//! Re-exports of quantity types specialized to `i16` scalar.
|
|
2
|
+
//!
|
|
3
|
+
//! This module provides type aliases for all unit types using `i16` as the
|
|
4
|
+
//! underlying scalar type. Integer quantities provide compile-time unit safety
|
|
5
|
+
//! for discrete values (counters, pixel coordinates, ADC readings, etc.).
|
|
6
|
+
//!
|
|
7
|
+
//! Integer quantities support basic arithmetic but **not** unit conversion via
|
|
8
|
+
//! [`to()`](crate::Quantity::to). Use [`to_lossy()`](crate::Quantity::to_lossy)
|
|
9
|
+
//! for lossy (truncating) conversion between units.
|
|
10
|
+
//!
|
|
11
|
+
//! # Example
|
|
12
|
+
//!
|
|
13
|
+
//! ```rust
|
|
14
|
+
//! use qtty::i16::{Meters, Seconds};
|
|
15
|
+
//!
|
|
16
|
+
//! let distance: Meters = Meters::new(1500);
|
|
17
|
+
//! let time: Seconds = Seconds::new(10);
|
|
18
|
+
//! ```
|
|
19
|
+
|
|
20
|
+
use crate::Quantity;
|
|
21
|
+
|
|
22
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
23
|
+
// Angular units (i16)
|
|
24
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
/// Degrees with `i16` scalar.
|
|
27
|
+
pub type Degrees = Quantity<crate::angular::Degree, i16>;
|
|
28
|
+
/// Radians with `i16` scalar.
|
|
29
|
+
pub type Radians = Quantity<crate::angular::Radian, i16>;
|
|
30
|
+
/// Arcminutes with `i16` scalar.
|
|
31
|
+
pub type Arcminutes = Quantity<crate::angular::Arcminute, i16>;
|
|
32
|
+
/// Arcseconds with `i16` scalar.
|
|
33
|
+
pub type Arcseconds = Quantity<crate::angular::Arcsecond, i16>;
|
|
34
|
+
/// Milliradians with `i16` scalar.
|
|
35
|
+
pub type Milliradians = Quantity<crate::angular::Milliradian, i16>;
|
|
36
|
+
/// Milliarcseconds with `i16` scalar.
|
|
37
|
+
pub type MilliArcseconds = Quantity<crate::angular::MilliArcsecond, i16>;
|
|
38
|
+
/// Microarcseconds with `i16` scalar.
|
|
39
|
+
pub type MicroArcseconds = Quantity<crate::angular::MicroArcsecond, i16>;
|
|
40
|
+
/// Gradians with `i16` scalar.
|
|
41
|
+
pub type Gradians = Quantity<crate::angular::Gradian, i16>;
|
|
42
|
+
/// Turns with `i16` scalar.
|
|
43
|
+
pub type Turns = Quantity<crate::angular::Turn, i16>;
|
|
44
|
+
/// Hour angles with `i16` scalar.
|
|
45
|
+
pub type HourAngles = Quantity<crate::angular::HourAngle, i16>;
|
|
46
|
+
|
|
47
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
48
|
+
// Length units (i16)
|
|
49
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
50
|
+
|
|
51
|
+
/// Meters with `i16` scalar.
|
|
52
|
+
pub type Meters = Quantity<crate::length::Meter, i16>;
|
|
53
|
+
/// Kilometers with `i16` scalar.
|
|
54
|
+
pub type Kilometers = Quantity<crate::length::Kilometer, i16>;
|
|
55
|
+
/// Centimeters with `i16` scalar.
|
|
56
|
+
pub type Centimeters = Quantity<crate::length::Centimeter, i16>;
|
|
57
|
+
/// Millimeters with `i16` scalar.
|
|
58
|
+
pub type Millimeters = Quantity<crate::length::Millimeter, i16>;
|
|
59
|
+
/// Micrometers with `i16` scalar.
|
|
60
|
+
pub type Micrometers = Quantity<crate::length::Micrometer, i16>;
|
|
61
|
+
/// Nanometers with `i16` scalar.
|
|
62
|
+
pub type Nanometers = Quantity<crate::length::Nanometer, i16>;
|
|
63
|
+
/// Astronomical units with `i16` scalar.
|
|
64
|
+
pub type AstronomicalUnits = Quantity<crate::length::AstronomicalUnit, i16>;
|
|
65
|
+
/// Light years with `i16` scalar.
|
|
66
|
+
pub type LightYears = Quantity<crate::length::LightYear, i16>;
|
|
67
|
+
/// Parsecs with `i16` scalar.
|
|
68
|
+
pub type Parsecs = Quantity<crate::length::Parsec, i16>;
|
|
69
|
+
|
|
70
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
71
|
+
// Time units (i16)
|
|
72
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
/// Seconds with `i16` scalar.
|
|
75
|
+
pub type Seconds = Quantity<crate::time::Second, i16>;
|
|
76
|
+
/// Milliseconds with `i16` scalar.
|
|
77
|
+
pub type Milliseconds = Quantity<crate::time::Millisecond, i16>;
|
|
78
|
+
/// Microseconds with `i16` scalar.
|
|
79
|
+
pub type Microseconds = Quantity<crate::time::Microsecond, i16>;
|
|
80
|
+
/// Nanoseconds with `i16` scalar.
|
|
81
|
+
pub type Nanoseconds = Quantity<crate::time::Nanosecond, i16>;
|
|
82
|
+
/// Minutes with `i16` scalar.
|
|
83
|
+
pub type Minutes = Quantity<crate::time::Minute, i16>;
|
|
84
|
+
/// Hours with `i16` scalar.
|
|
85
|
+
pub type Hours = Quantity<crate::time::Hour, i16>;
|
|
86
|
+
/// Days with `i16` scalar.
|
|
87
|
+
pub type Days = Quantity<crate::time::Day, i16>;
|
|
88
|
+
/// Years with `i16` scalar.
|
|
89
|
+
pub type Years = Quantity<crate::time::Year, i16>;
|
|
90
|
+
|
|
91
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
92
|
+
// Mass units (i16)
|
|
93
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
94
|
+
|
|
95
|
+
/// Grams with `i16` scalar.
|
|
96
|
+
pub type Grams = Quantity<crate::mass::Gram, i16>;
|
|
97
|
+
/// Kilograms with `i16` scalar.
|
|
98
|
+
pub type Kilograms = Quantity<crate::mass::Kilogram, i16>;
|
|
99
|
+
/// Solar masses with `i16` scalar.
|
|
100
|
+
pub type SolarMasses = Quantity<crate::mass::SolarMass, i16>;
|
|
101
|
+
|
|
102
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
103
|
+
// Power units (i16)
|
|
104
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
105
|
+
|
|
106
|
+
/// Watts with `i16` scalar.
|
|
107
|
+
pub type Watts = Quantity<crate::power::Watt, i16>;
|
|
108
|
+
/// Kilowatts with `i16` scalar.
|
|
109
|
+
pub type Kilowatts = Quantity<crate::power::Kilowatt, i16>;
|
|
110
|
+
/// Solar luminosities with `i16` scalar.
|
|
111
|
+
pub type SolarLuminosities = Quantity<crate::power::SolarLuminosity, i16>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
//! Re-exports of quantity types specialized to `i32` scalar.
|
|
2
|
+
//!
|
|
3
|
+
//! This module provides type aliases for all unit types using `i32` as the
|
|
4
|
+
//! underlying scalar type. Integer quantities provide compile-time unit safety
|
|
5
|
+
//! for discrete values (counters, pixel coordinates, ADC readings, etc.).
|
|
6
|
+
//!
|
|
7
|
+
//! Integer quantities support basic arithmetic but **not** unit conversion via
|
|
8
|
+
//! [`to()`](crate::Quantity::to). Use [`to_lossy()`](crate::Quantity::to_lossy)
|
|
9
|
+
//! for lossy (truncating) conversion between units.
|
|
10
|
+
//!
|
|
11
|
+
//! # Example
|
|
12
|
+
//!
|
|
13
|
+
//! ```rust
|
|
14
|
+
//! use qtty::i32::{Meters, Seconds};
|
|
15
|
+
//!
|
|
16
|
+
//! let distance: Meters = Meters::new(1500);
|
|
17
|
+
//! let time: Seconds = Seconds::new(10);
|
|
18
|
+
//! ```
|
|
19
|
+
|
|
20
|
+
use crate::Quantity;
|
|
21
|
+
|
|
22
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
23
|
+
// Angular units (i32)
|
|
24
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
/// Degrees with `i32` scalar.
|
|
27
|
+
pub type Degrees = Quantity<crate::angular::Degree, i32>;
|
|
28
|
+
/// Radians with `i32` scalar.
|
|
29
|
+
pub type Radians = Quantity<crate::angular::Radian, i32>;
|
|
30
|
+
/// Arcminutes with `i32` scalar.
|
|
31
|
+
pub type Arcminutes = Quantity<crate::angular::Arcminute, i32>;
|
|
32
|
+
/// Arcseconds with `i32` scalar.
|
|
33
|
+
pub type Arcseconds = Quantity<crate::angular::Arcsecond, i32>;
|
|
34
|
+
/// Milliradians with `i32` scalar.
|
|
35
|
+
pub type Milliradians = Quantity<crate::angular::Milliradian, i32>;
|
|
36
|
+
/// Milliarcseconds with `i32` scalar.
|
|
37
|
+
pub type MilliArcseconds = Quantity<crate::angular::MilliArcsecond, i32>;
|
|
38
|
+
/// Microarcseconds with `i32` scalar.
|
|
39
|
+
pub type MicroArcseconds = Quantity<crate::angular::MicroArcsecond, i32>;
|
|
40
|
+
/// Gradians with `i32` scalar.
|
|
41
|
+
pub type Gradians = Quantity<crate::angular::Gradian, i32>;
|
|
42
|
+
/// Turns with `i32` scalar.
|
|
43
|
+
pub type Turns = Quantity<crate::angular::Turn, i32>;
|
|
44
|
+
/// Hour angles with `i32` scalar.
|
|
45
|
+
pub type HourAngles = Quantity<crate::angular::HourAngle, i32>;
|
|
46
|
+
|
|
47
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
48
|
+
// Length units (i32)
|
|
49
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
50
|
+
|
|
51
|
+
/// Meters with `i32` scalar.
|
|
52
|
+
pub type Meters = Quantity<crate::length::Meter, i32>;
|
|
53
|
+
/// Kilometers with `i32` scalar.
|
|
54
|
+
pub type Kilometers = Quantity<crate::length::Kilometer, i32>;
|
|
55
|
+
/// Centimeters with `i32` scalar.
|
|
56
|
+
pub type Centimeters = Quantity<crate::length::Centimeter, i32>;
|
|
57
|
+
/// Millimeters with `i32` scalar.
|
|
58
|
+
pub type Millimeters = Quantity<crate::length::Millimeter, i32>;
|
|
59
|
+
/// Micrometers with `i32` scalar.
|
|
60
|
+
pub type Micrometers = Quantity<crate::length::Micrometer, i32>;
|
|
61
|
+
/// Nanometers with `i32` scalar.
|
|
62
|
+
pub type Nanometers = Quantity<crate::length::Nanometer, i32>;
|
|
63
|
+
/// Astronomical units with `i32` scalar.
|
|
64
|
+
pub type AstronomicalUnits = Quantity<crate::length::AstronomicalUnit, i32>;
|
|
65
|
+
/// Light years with `i32` scalar.
|
|
66
|
+
pub type LightYears = Quantity<crate::length::LightYear, i32>;
|
|
67
|
+
/// Parsecs with `i32` scalar.
|
|
68
|
+
pub type Parsecs = Quantity<crate::length::Parsec, i32>;
|
|
69
|
+
|
|
70
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
71
|
+
// Time units (i32)
|
|
72
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
/// Seconds with `i32` scalar.
|
|
75
|
+
pub type Seconds = Quantity<crate::time::Second, i32>;
|
|
76
|
+
/// Milliseconds with `i32` scalar.
|
|
77
|
+
pub type Milliseconds = Quantity<crate::time::Millisecond, i32>;
|
|
78
|
+
/// Microseconds with `i32` scalar.
|
|
79
|
+
pub type Microseconds = Quantity<crate::time::Microsecond, i32>;
|
|
80
|
+
/// Nanoseconds with `i32` scalar.
|
|
81
|
+
pub type Nanoseconds = Quantity<crate::time::Nanosecond, i32>;
|
|
82
|
+
/// Minutes with `i32` scalar.
|
|
83
|
+
pub type Minutes = Quantity<crate::time::Minute, i32>;
|
|
84
|
+
/// Hours with `i32` scalar.
|
|
85
|
+
pub type Hours = Quantity<crate::time::Hour, i32>;
|
|
86
|
+
/// Days with `i32` scalar.
|
|
87
|
+
pub type Days = Quantity<crate::time::Day, i32>;
|
|
88
|
+
/// Years with `i32` scalar.
|
|
89
|
+
pub type Years = Quantity<crate::time::Year, i32>;
|
|
90
|
+
|
|
91
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
92
|
+
// Mass units (i32)
|
|
93
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
94
|
+
|
|
95
|
+
/// Grams with `i32` scalar.
|
|
96
|
+
pub type Grams = Quantity<crate::mass::Gram, i32>;
|
|
97
|
+
/// Kilograms with `i32` scalar.
|
|
98
|
+
pub type Kilograms = Quantity<crate::mass::Kilogram, i32>;
|
|
99
|
+
/// Solar masses with `i32` scalar.
|
|
100
|
+
pub type SolarMasses = Quantity<crate::mass::SolarMass, i32>;
|
|
101
|
+
|
|
102
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
103
|
+
// Power units (i32)
|
|
104
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
105
|
+
|
|
106
|
+
/// Watts with `i32` scalar.
|
|
107
|
+
pub type Watts = Quantity<crate::power::Watt, i32>;
|
|
108
|
+
/// Kilowatts with `i32` scalar.
|
|
109
|
+
pub type Kilowatts = Quantity<crate::power::Kilowatt, i32>;
|
|
110
|
+
/// Solar luminosities with `i32` scalar.
|
|
111
|
+
pub type SolarLuminosities = Quantity<crate::power::SolarLuminosity, i32>;
|