1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//! # iridium-units
//!
//! A high-performance runtime dimensional analysis library for Rust.
//!
//! This library provides physical units and quantities with automatic dimensional
//! analysis at runtime. It supports SI, CGS, and astrophysical unit systems,
//! as well as equivalencies for converting between different physical domains
//! (e.g., wavelength to frequency).
//!
//! ## Quick Start
//!
//! ```
//! use iridium_units::prelude::*;
//!
//! // Create quantities by multiplying values with units
//! // Units are const values — use them directly
//! let distance = 100.0 * M;
//! let time = 9.58 * S;
//! let speed = &distance / &time;
//!
//! // Convert between units
//! let speed_kmh = speed.to(&(KM / H)).unwrap();
//! println!("{}", speed_kmh); // ~37.58 km / h
//!
//! // Dimensional analysis is automatic
//! let energy = 10.0 * KG * M.pow(2) / S.pow(2);
//! let in_joules = energy.to(J).unwrap();
//! ```
//!
//! ## Unit Systems
//!
//! The library provides units from multiple systems:
//!
//! - **SI units**: meter, second, kilogram, ampere, kelvin, etc.
//! - **CGS units**: centimeter, gram, dyne, erg, etc.
//! - **Astrophysical units**: parsec, AU, solar mass, light year, etc.
//! - **Imperial units**: mile, foot, inch, pound, etc.
//!
//! ## Parsing Units and Quantities
//!
//! Units and quantities can be parsed from strings with flexible syntax support:
//!
//! ```no_run
//! # #[cfg(feature = "astrophysics")]
//! # fn main() {
//! use iridium_units::prelude::*;
//! use std::str::FromStr;
//!
//! // Parse units from strings
//! let meter = Unit::from_str("m").unwrap();
//! let velocity_unit = Unit::from_str("km/s").unwrap();
//! let accel_unit = Unit::from_str("m/s^2").unwrap();
//!
//! // Parse quantities (value + unit)
//! let distance: Quantity = "100 km".parse().unwrap();
//! let speed: Quantity = "9.8 m/s^2".parse().unwrap();
//!
//! // Unicode and technical formats are supported
//! let area = parse_unit("m²").unwrap(); // Unicode superscript
//! let wavelength = parse_unit("µm").unwrap(); // Unicode micro
//! let flux = parse_unit("erg/cm²/s").unwrap(); // Astrophysical
//! let latex = parse_unit("kg m^{2} / s^{2}").unwrap(); // LaTeX braces
//! let natural = parse_unit("km per hour").unwrap(); // Natural language
//! let astro = parse_unit("M_sun").unwrap(); // Astrophysical subscripts
//! let parens = parse_unit("(kg m)/s^2").unwrap(); // Parentheses
//! # }
//! # #[cfg(not(feature = "astrophysics"))]
//! # fn main() {}
//! ```
//!
//! See the [`parsing`] module for comprehensive documentation of supported formats.
//!
//! ## Custom Unit Registry
//!
//! For applications needing custom units (e.g., loaded from a database):
//!
//! ```
//! use iridium_units::prelude::*;
//!
//! let registry = UnitRegistry::with_builtins()
//! .with_unit(&["my_unit", "mu"], Unit::from(M));
//!
//! let unit = registry.parse_unit("my_unit").unwrap();
//! ```
//!
//! ## Equivalencies
//!
//! Some physical quantities can be converted through physical laws even though
//! they have different dimensions:
//!
//! ```no_run
//! # #[cfg(feature = "astrophysics")]
//! # fn main() {
//! use iridium_units::prelude::*;
//! use iridium_units::equivalencies::spectral;
//!
//! let wavelength = 500.0 * NM;
//! let frequency = wavelength.to_equiv(HZ, spectral()).unwrap();
//! # }
//! # #[cfg(not(feature = "astrophysics"))]
//! # fn main() {}
//! ```
// Re-export main types
pub use ;
pub use ;
pub use ;
pub use BaseUnit;
pub use Unit;
// Re-export parsing functions and types
pub use ;
/// Prelude module for convenient imports.
///
/// This module re-exports the most commonly used types and units.
///
/// ```
/// use iridium_units::prelude::*;
/// ```