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
//! Atomic-weight convenience values for elements.
//!
//! For elements without a CIAAW standard atomic weight, this module still
//! exposes a representative single value for compatibility.
impl crate::Element {
#[allow(clippy::too_many_lines)]
/// Returns the crate's single-value atomic-weight convenience value.
///
/// For elements with a CIAAW standard atomic weight, this is the
/// single-value form used by the crate. For elements without a CIAAW
/// standard atomic weight, this method still returns a representative
/// fallback value for compatibility, typically following the bracketed
/// value used in the [IUPAC periodic table].
///
/// This means the result should not always be interpreted as a literal
/// CIAAW standard atomic weight.
///
/// [IUPAC periodic table]: https://iupac.org/what-we-do/periodic-table-of-elements/
///
/// # Examples
///
/// ```rust
/// use elements_rs::Element;
///
/// assert_eq!(Element::H.standard_atomic_weight(), 1.008);
/// assert_eq!(Element::O.standard_atomic_weight(), 15.999);
/// ```
#[must_use]
pub fn standard_atomic_weight(&self) -> f64 {
match self {
Self::H => 1.008,
Self::He => 4.002602,
Self::Li => 6.94,
Self::Be => 9.0121831,
Self::B => 10.81,
Self::C => 12.011,
Self::N => 14.007,
Self::O => 15.999,
Self::F => 18.998,
Self::Ne => 20.1797,
Self::Na => 22.99,
Self::Mg => 24.305,
Self::Al => 26.9815385,
Self::Si => 28.085,
Self::P => 30.973761998,
Self::S => 32.06,
Self::Cl => 35.45,
Self::Ar => 39.948,
Self::K => 39.0983,
Self::Ca => 40.078,
Self::Sc => 44.955908,
Self::Ti => 47.867,
Self::V => 50.9415,
Self::Cr => 51.9961,
Self::Mn => 54.938044,
Self::Fe => 55.845,
Self::Co => 58.933194,
Self::Ni => 58.6934,
Self::Cu => 63.546,
Self::Zn => 65.38,
Self::Ga => 69.723,
Self::Ge => 72.63,
Self::As => 74.921595,
Self::Se => 78.971,
Self::Br => 79.904,
Self::Kr => 83.798,
Self::Rb => 85.4678,
Self::Sr => 87.62,
Self::Y => 88.90584,
Self::Zr => 91.224,
Self::Nb => 92.90637,
Self::Mo => 95.95,
Self::Tc => 97.90721,
Self::Ru => 101.07,
Self::Rh => 102.9055,
Self::Pd => 106.42,
Self::Ag => 107.8682,
Self::Cd => 112.414,
Self::In => 114.818,
Self::Sn => 118.71,
Self::Sb => 121.76,
Self::Te => 127.6,
Self::I => 126.90447,
Self::Xe => 131.293,
Self::Cs => 132.90545196,
Self::Ba => 137.327,
Self::La => 138.90547,
Self::Ce => 140.116,
Self::Pr => 140.90766,
Self::Nd => 144.242,
Self::Pm => 144.91276,
Self::Sm => 150.36,
Self::Eu => 151.964,
Self::Gd => 157.25,
Self::Tb => 158.92535,
Self::Dy => 162.5,
Self::Ho => 164.93033,
Self::Er => 167.259,
Self::Tm => 168.93422,
Self::Yb => 173.045,
Self::Lu => 174.9668,
Self::Hf => 178.49,
Self::Ta => 180.94788,
Self::W => 183.84,
Self::Re => 186.207,
Self::Os => 190.23,
Self::Ir => 192.217,
Self::Pt => 195.084,
Self::Au => 196.966569,
Self::Hg => 200.592,
Self::Tl => 204.38,
Self::Pb => 207.2,
Self::Bi => 208.9804,
Self::Po => 209.0,
Self::At => 210.0,
Self::Rn => 222.0,
Self::Fr => 223.0,
Self::Ra => 226.0,
Self::Ac => 227.0,
Self::Th => 232.0377,
Self::Pa => 231.03588,
Self::U => 238.02891,
Self::Np => 237.0,
Self::Pu => 244.0,
Self::Am => 243.0,
Self::Cm | Self::Bk => 247.0,
Self::Cf => 251.0,
Self::Es => 252.0,
Self::Fm => 257.0,
Self::Md => 258.0,
Self::No => 259.0,
Self::Lr => 262.0,
Self::Rf => 267.0,
Self::Db => 268.0,
Self::Sg | Self::Hs => 269.0,
Self::Bh => 270.0,
Self::Mt => 277.0,
Self::Ds => 281.0,
Self::Rg => 282.0,
Self::Cn => 285.0,
Self::Nh => 286.0,
Self::Fl | Self::Mc => 290.0,
Self::Lv => 293.0,
Self::Ts | Self::Og => 294.0,
}
}
}
#[cfg(test)]
mod tests {
use strum::IntoEnumIterator;
#[test]
fn test_atomic_weight_values_are_positive() {
for element in crate::Element::iter() {
let weight = element.standard_atomic_weight();
assert!(weight > 0.0, "Atomic-weight value should be positive for {element:?}");
}
}
#[test]
fn test_updated_iupac_periodic_table_fallback_values() {
for (element, expected) in [
(crate::Element::Sg, 269.0),
(crate::Element::Bh, 270.0),
(crate::Element::Mt, 277.0),
(crate::Element::Rg, 282.0),
(crate::Element::Fl, 290.0),
(crate::Element::Mc, 290.0),
] {
let weight = element.standard_atomic_weight();
assert!(
(weight - expected).abs() < f64::EPSILON,
"expected {expected} for {element:?}, got {weight}"
);
}
}
}