elements_rs 0.2.6

A comprehensive library for chemical elements and their isotopes with rich metadata
Documentation
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
//! Isotopes of the element Silver
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, strum :: EnumIter)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "mem_size", derive(mem_dbg::MemSize))]
#[cfg_attr(feature = "mem_dbg", derive(mem_dbg::MemDbg))]
#[cfg_attr(feature = "mem_size", mem_size(flat))]
/// Isotopes of the element Silver
pub enum SilverIsotope {
    /// Isotope Ag92 of Silver
    Ag92,
    /// Isotope Ag93 of Silver
    Ag93,
    /// Isotope Ag94 of Silver
    Ag94,
    /// Isotope Ag95 of Silver
    Ag95,
    /// Isotope Ag96 of Silver
    Ag96,
    /// Isotope Ag97 of Silver
    Ag97,
    /// Isotope Ag98 of Silver
    Ag98,
    /// Isotope Ag99 of Silver
    Ag99,
    /// Isotope Ag100 of Silver
    Ag100,
    /// Isotope Ag101 of Silver
    Ag101,
    /// Isotope Ag102 of Silver
    Ag102,
    /// Isotope Ag103 of Silver
    Ag103,
    /// Isotope Ag104 of Silver
    Ag104,
    /// Isotope Ag105 of Silver
    Ag105,
    /// Isotope Ag106 of Silver
    Ag106,
    /// Isotope Ag107 of Silver
    Ag107,
    /// Isotope Ag108 of Silver
    Ag108,
    /// Isotope Ag109 of Silver
    Ag109,
    /// Isotope Ag110 of Silver
    Ag110,
    /// Isotope Ag111 of Silver
    Ag111,
    /// Isotope Ag112 of Silver
    Ag112,
    /// Isotope Ag113 of Silver
    Ag113,
    /// Isotope Ag114 of Silver
    Ag114,
    /// Isotope Ag115 of Silver
    Ag115,
    /// Isotope Ag116 of Silver
    Ag116,
    /// Isotope Ag117 of Silver
    Ag117,
    /// Isotope Ag118 of Silver
    Ag118,
    /// Isotope Ag119 of Silver
    Ag119,
    /// Isotope Ag120 of Silver
    Ag120,
    /// Isotope Ag121 of Silver
    Ag121,
    /// Isotope Ag122 of Silver
    Ag122,
    /// Isotope Ag123 of Silver
    Ag123,
    /// Isotope Ag124 of Silver
    Ag124,
    /// Isotope Ag125 of Silver
    Ag125,
    /// Isotope Ag126 of Silver
    Ag126,
    /// Isotope Ag127 of Silver
    Ag127,
    /// Isotope Ag128 of Silver
    Ag128,
    /// Isotope Ag129 of Silver
    Ag129,
    /// Isotope Ag130 of Silver
    Ag130,
    /// Isotope Ag131 of Silver
    Ag131,
    /// Isotope Ag132 of Silver
    Ag132,
}
impl super::RelativeAtomicMass for SilverIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Ag92 => 91.95971f64,
            Self::Ag93 => 92.95033f64,
            Self::Ag94 => 93.94373f64,
            Self::Ag95 => 94.93602f64,
            Self::Ag96 => 95.930744f64,
            Self::Ag97 => 96.92397f64,
            Self::Ag98 => 97.92156f64,
            Self::Ag99 => 98.9176458f64,
            Self::Ag100 => 99.9161154f64,
            Self::Ag101 => 100.912684f64,
            Self::Ag102 => 101.9117047f64,
            Self::Ag103 => 102.9089631f64,
            Self::Ag104 => 103.9086239f64,
            Self::Ag105 => 104.9065256f64,
            Self::Ag106 => 105.9066636f64,
            Self::Ag107 => 106.9050916f64,
            Self::Ag108 => 107.9059503f64,
            Self::Ag109 => 108.9047553f64,
            Self::Ag110 => 109.9061102f64,
            Self::Ag111 => 110.9052959f64,
            Self::Ag112 => 111.9070486f64,
            Self::Ag113 => 112.906573f64,
            Self::Ag114 => 113.908823f64,
            Self::Ag115 => 114.908767f64,
            Self::Ag116 => 115.9113868f64,
            Self::Ag117 => 116.911774f64,
            Self::Ag118 => 117.9145955f64,
            Self::Ag119 => 118.91557f64,
            Self::Ag120 => 119.9187848f64,
            Self::Ag121 => 120.920125f64,
            Self::Ag122 => 121.923664f64,
            Self::Ag123 => 122.925337f64,
            Self::Ag124 => 123.92893f64,
            Self::Ag125 => 124.93105f64,
            Self::Ag126 => 125.93475f64,
            Self::Ag127 => 126.93711f64,
            Self::Ag128 => 127.94106f64,
            Self::Ag129 => 128.94395f64,
            Self::Ag130 => 129.9507f64,
            Self::Ag131 => 130.956253f64,
            Self::Ag132 => 131.96307f64,
        }
    }
}
impl super::ElementVariant for SilverIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Ag
    }
}
impl super::MassNumber for SilverIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Ag92 => 92u16,
            Self::Ag93 => 93u16,
            Self::Ag94 => 94u16,
            Self::Ag95 => 95u16,
            Self::Ag96 => 96u16,
            Self::Ag97 => 97u16,
            Self::Ag98 => 98u16,
            Self::Ag99 => 99u16,
            Self::Ag100 => 100u16,
            Self::Ag101 => 101u16,
            Self::Ag102 => 102u16,
            Self::Ag103 => 103u16,
            Self::Ag104 => 104u16,
            Self::Ag105 => 105u16,
            Self::Ag106 => 106u16,
            Self::Ag107 => 107u16,
            Self::Ag108 => 108u16,
            Self::Ag109 => 109u16,
            Self::Ag110 => 110u16,
            Self::Ag111 => 111u16,
            Self::Ag112 => 112u16,
            Self::Ag113 => 113u16,
            Self::Ag114 => 114u16,
            Self::Ag115 => 115u16,
            Self::Ag116 => 116u16,
            Self::Ag117 => 117u16,
            Self::Ag118 => 118u16,
            Self::Ag119 => 119u16,
            Self::Ag120 => 120u16,
            Self::Ag121 => 121u16,
            Self::Ag122 => 122u16,
            Self::Ag123 => 123u16,
            Self::Ag124 => 124u16,
            Self::Ag125 => 125u16,
            Self::Ag126 => 126u16,
            Self::Ag127 => 127u16,
            Self::Ag128 => 128u16,
            Self::Ag129 => 129u16,
            Self::Ag130 => 130u16,
            Self::Ag131 => 131u16,
            Self::Ag132 => 132u16,
        }
    }
}
impl super::IsotopicComposition for SilverIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Ag107 => Some(0.51839f64),
            Self::Ag109 => Some(0.48161f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for SilverIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Ag107
    }
}
impl From<SilverIsotope> for crate::Isotope {
    fn from(isotope: SilverIsotope) -> Self {
        crate::Isotope::Ag(isotope)
    }
}
impl From<SilverIsotope> for crate::Element {
    fn from(_isotope: SilverIsotope) -> Self {
        crate::Element::Ag
    }
}
impl TryFrom<u64> for SilverIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            92u64 => Ok(Self::Ag92),
            93u64 => Ok(Self::Ag93),
            94u64 => Ok(Self::Ag94),
            95u64 => Ok(Self::Ag95),
            96u64 => Ok(Self::Ag96),
            97u64 => Ok(Self::Ag97),
            98u64 => Ok(Self::Ag98),
            99u64 => Ok(Self::Ag99),
            100u64 => Ok(Self::Ag100),
            101u64 => Ok(Self::Ag101),
            102u64 => Ok(Self::Ag102),
            103u64 => Ok(Self::Ag103),
            104u64 => Ok(Self::Ag104),
            105u64 => Ok(Self::Ag105),
            106u64 => Ok(Self::Ag106),
            107u64 => Ok(Self::Ag107),
            108u64 => Ok(Self::Ag108),
            109u64 => Ok(Self::Ag109),
            110u64 => Ok(Self::Ag110),
            111u64 => Ok(Self::Ag111),
            112u64 => Ok(Self::Ag112),
            113u64 => Ok(Self::Ag113),
            114u64 => Ok(Self::Ag114),
            115u64 => Ok(Self::Ag115),
            116u64 => Ok(Self::Ag116),
            117u64 => Ok(Self::Ag117),
            118u64 => Ok(Self::Ag118),
            119u64 => Ok(Self::Ag119),
            120u64 => Ok(Self::Ag120),
            121u64 => Ok(Self::Ag121),
            122u64 => Ok(Self::Ag122),
            123u64 => Ok(Self::Ag123),
            124u64 => Ok(Self::Ag124),
            125u64 => Ok(Self::Ag125),
            126u64 => Ok(Self::Ag126),
            127u64 => Ok(Self::Ag127),
            128u64 => Ok(Self::Ag128),
            129u64 => Ok(Self::Ag129),
            130u64 => Ok(Self::Ag130),
            131u64 => Ok(Self::Ag131),
            132u64 => Ok(Self::Ag132),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Ag, value)),
        }
    }
}
impl TryFrom<u8> for SilverIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for SilverIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for SilverIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u32) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl core::fmt::Display for SilverIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Ag92 => write!(f, "Ag92"),
            Self::Ag93 => write!(f, "Ag93"),
            Self::Ag94 => write!(f, "Ag94"),
            Self::Ag95 => write!(f, "Ag95"),
            Self::Ag96 => write!(f, "Ag96"),
            Self::Ag97 => write!(f, "Ag97"),
            Self::Ag98 => write!(f, "Ag98"),
            Self::Ag99 => write!(f, "Ag99"),
            Self::Ag100 => write!(f, "Ag100"),
            Self::Ag101 => write!(f, "Ag101"),
            Self::Ag102 => write!(f, "Ag102"),
            Self::Ag103 => write!(f, "Ag103"),
            Self::Ag104 => write!(f, "Ag104"),
            Self::Ag105 => write!(f, "Ag105"),
            Self::Ag106 => write!(f, "Ag106"),
            Self::Ag107 => write!(f, "Ag107"),
            Self::Ag108 => write!(f, "Ag108"),
            Self::Ag109 => write!(f, "Ag109"),
            Self::Ag110 => write!(f, "Ag110"),
            Self::Ag111 => write!(f, "Ag111"),
            Self::Ag112 => write!(f, "Ag112"),
            Self::Ag113 => write!(f, "Ag113"),
            Self::Ag114 => write!(f, "Ag114"),
            Self::Ag115 => write!(f, "Ag115"),
            Self::Ag116 => write!(f, "Ag116"),
            Self::Ag117 => write!(f, "Ag117"),
            Self::Ag118 => write!(f, "Ag118"),
            Self::Ag119 => write!(f, "Ag119"),
            Self::Ag120 => write!(f, "Ag120"),
            Self::Ag121 => write!(f, "Ag121"),
            Self::Ag122 => write!(f, "Ag122"),
            Self::Ag123 => write!(f, "Ag123"),
            Self::Ag124 => write!(f, "Ag124"),
            Self::Ag125 => write!(f, "Ag125"),
            Self::Ag126 => write!(f, "Ag126"),
            Self::Ag127 => write!(f, "Ag127"),
            Self::Ag128 => write!(f, "Ag128"),
            Self::Ag129 => write!(f, "Ag129"),
            Self::Ag130 => write!(f, "Ag130"),
            Self::Ag131 => write!(f, "Ag131"),
            Self::Ag132 => write!(f, "Ag132"),
        }
    }
}
#[cfg(test)]
mod tests {
    use strum::IntoEnumIterator;

    use super::*;
    use crate::isotopes::{
        ElementVariant, IsotopicComposition, MassNumber, MostAbundantIsotope, RelativeAtomicMass,
    };
    #[test]
    fn test_relative_atomic_mass() {
        for isotope in SilverIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in SilverIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Ag, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in SilverIsotope::iter() {
            let mass_number = isotope.mass_number();
            assert!(
                mass_number > 0 && mass_number < 300,
                "Mass number should be reasonable for {isotope:?}"
            );
        }
    }
    #[test]
    fn test_isotopic_composition() {
        for isotope in SilverIsotope::iter() {
            let comp = isotope.isotopic_composition();
            if let Some(c) = comp {
                assert!(
                    (0.0..=1.0).contains(&c),
                    "Composition should be between 0 and 1 for {isotope:?}"
                );
            }
        }
    }
    #[test]
    fn test_most_abundant() {
        let most_abundant = SilverIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in SilverIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Ag(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in SilverIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Ag);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in SilverIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = SilverIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = SilverIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = SilverIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(SilverIsotope::try_from(0_u16).is_err());
        assert!(SilverIsotope::try_from(1000_u16).is_err());
        assert!(SilverIsotope::try_from(0_u32).is_err());
        assert!(SilverIsotope::try_from(1000_u32).is_err());
        assert!(SilverIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in SilverIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}