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
//! Isotopes of the element Technetium
#[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 Technetium
pub enum TechnetiumIsotope {
    /// Isotope Tc85 of Technetium
    Tc85,
    /// Isotope Tc86 of Technetium
    Tc86,
    /// Isotope Tc87 of Technetium
    Tc87,
    /// Isotope Tc88 of Technetium
    Tc88,
    /// Isotope Tc89 of Technetium
    Tc89,
    /// Isotope Tc90 of Technetium
    Tc90,
    /// Isotope Tc91 of Technetium
    Tc91,
    /// Isotope Tc92 of Technetium
    Tc92,
    /// Isotope Tc93 of Technetium
    Tc93,
    /// Isotope Tc94 of Technetium
    Tc94,
    /// Isotope Tc95 of Technetium
    Tc95,
    /// Isotope Tc96 of Technetium
    Tc96,
    /// Isotope Tc97 of Technetium
    Tc97,
    /// Isotope Tc98 of Technetium
    Tc98,
    /// Isotope Tc99 of Technetium
    Tc99,
    /// Isotope Tc100 of Technetium
    Tc100,
    /// Isotope Tc101 of Technetium
    Tc101,
    /// Isotope Tc102 of Technetium
    Tc102,
    /// Isotope Tc103 of Technetium
    Tc103,
    /// Isotope Tc104 of Technetium
    Tc104,
    /// Isotope Tc105 of Technetium
    Tc105,
    /// Isotope Tc106 of Technetium
    Tc106,
    /// Isotope Tc107 of Technetium
    Tc107,
    /// Isotope Tc108 of Technetium
    Tc108,
    /// Isotope Tc109 of Technetium
    Tc109,
    /// Isotope Tc110 of Technetium
    Tc110,
    /// Isotope Tc111 of Technetium
    Tc111,
    /// Isotope Tc112 of Technetium
    Tc112,
    /// Isotope Tc113 of Technetium
    Tc113,
    /// Isotope Tc114 of Technetium
    Tc114,
    /// Isotope Tc115 of Technetium
    Tc115,
    /// Isotope Tc116 of Technetium
    Tc116,
    /// Isotope Tc117 of Technetium
    Tc117,
    /// Isotope Tc118 of Technetium
    Tc118,
    /// Isotope Tc119 of Technetium
    Tc119,
    /// Isotope Tc120 of Technetium
    Tc120,
    /// Isotope Tc121 of Technetium
    Tc121,
    /// Isotope Tc122 of Technetium
    Tc122,
}
impl super::RelativeAtomicMass for TechnetiumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Tc85 => 84.95058f64,
            Self::Tc86 => 85.94493f64,
            Self::Tc87 => 86.9380672f64,
            Self::Tc88 => 87.93378f64,
            Self::Tc89 => 88.9276487f64,
            Self::Tc90 => 89.9240739f64,
            Self::Tc91 => 90.9184254f64,
            Self::Tc92 => 91.9152698f64,
            Self::Tc93 => 92.910246f64,
            Self::Tc94 => 93.9096536f64,
            Self::Tc95 => 94.9076536f64,
            Self::Tc96 => 95.907868f64,
            Self::Tc97 => 96.9063667f64,
            Self::Tc98 => 97.9072124f64,
            Self::Tc99 => 98.9062508f64,
            Self::Tc100 => 99.9076539f64,
            Self::Tc101 => 100.907309f64,
            Self::Tc102 => 101.9092097f64,
            Self::Tc103 => 102.909176f64,
            Self::Tc104 => 103.911425f64,
            Self::Tc105 => 104.911655f64,
            Self::Tc106 => 105.914358f64,
            Self::Tc107 => 106.9154606f64,
            Self::Tc108 => 107.9184957f64,
            Self::Tc109 => 108.920256f64,
            Self::Tc110 => 109.923744f64,
            Self::Tc111 => 110.925901f64,
            Self::Tc112 => 111.9299458f64,
            Self::Tc113 => 112.932569f64,
            Self::Tc114 => 113.93691f64,
            Self::Tc115 => 114.93998f64,
            Self::Tc116 => 115.94476f64,
            Self::Tc117 => 116.94806f64,
            Self::Tc118 => 117.95299f64,
            Self::Tc119 => 118.95666f64,
            Self::Tc120 => 119.96187f64,
            Self::Tc121 => 120.96614f64,
            Self::Tc122 => 121.97176f64,
        }
    }
}
impl super::ElementVariant for TechnetiumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Tc
    }
}
impl super::MassNumber for TechnetiumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Tc85 => 85u16,
            Self::Tc86 => 86u16,
            Self::Tc87 => 87u16,
            Self::Tc88 => 88u16,
            Self::Tc89 => 89u16,
            Self::Tc90 => 90u16,
            Self::Tc91 => 91u16,
            Self::Tc92 => 92u16,
            Self::Tc93 => 93u16,
            Self::Tc94 => 94u16,
            Self::Tc95 => 95u16,
            Self::Tc96 => 96u16,
            Self::Tc97 => 97u16,
            Self::Tc98 => 98u16,
            Self::Tc99 => 99u16,
            Self::Tc100 => 100u16,
            Self::Tc101 => 101u16,
            Self::Tc102 => 102u16,
            Self::Tc103 => 103u16,
            Self::Tc104 => 104u16,
            Self::Tc105 => 105u16,
            Self::Tc106 => 106u16,
            Self::Tc107 => 107u16,
            Self::Tc108 => 108u16,
            Self::Tc109 => 109u16,
            Self::Tc110 => 110u16,
            Self::Tc111 => 111u16,
            Self::Tc112 => 112u16,
            Self::Tc113 => 113u16,
            Self::Tc114 => 114u16,
            Self::Tc115 => 115u16,
            Self::Tc116 => 116u16,
            Self::Tc117 => 117u16,
            Self::Tc118 => 118u16,
            Self::Tc119 => 119u16,
            Self::Tc120 => 120u16,
            Self::Tc121 => 121u16,
            Self::Tc122 => 122u16,
        }
    }
}
impl super::IsotopicComposition for TechnetiumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        None
    }
}
impl super::MostAbundantIsotope for TechnetiumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Tc122
    }
}
impl From<TechnetiumIsotope> for crate::Isotope {
    fn from(isotope: TechnetiumIsotope) -> Self {
        crate::Isotope::Tc(isotope)
    }
}
impl From<TechnetiumIsotope> for crate::Element {
    fn from(_isotope: TechnetiumIsotope) -> Self {
        crate::Element::Tc
    }
}
impl TryFrom<u64> for TechnetiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            85u64 => Ok(Self::Tc85),
            86u64 => Ok(Self::Tc86),
            87u64 => Ok(Self::Tc87),
            88u64 => Ok(Self::Tc88),
            89u64 => Ok(Self::Tc89),
            90u64 => Ok(Self::Tc90),
            91u64 => Ok(Self::Tc91),
            92u64 => Ok(Self::Tc92),
            93u64 => Ok(Self::Tc93),
            94u64 => Ok(Self::Tc94),
            95u64 => Ok(Self::Tc95),
            96u64 => Ok(Self::Tc96),
            97u64 => Ok(Self::Tc97),
            98u64 => Ok(Self::Tc98),
            99u64 => Ok(Self::Tc99),
            100u64 => Ok(Self::Tc100),
            101u64 => Ok(Self::Tc101),
            102u64 => Ok(Self::Tc102),
            103u64 => Ok(Self::Tc103),
            104u64 => Ok(Self::Tc104),
            105u64 => Ok(Self::Tc105),
            106u64 => Ok(Self::Tc106),
            107u64 => Ok(Self::Tc107),
            108u64 => Ok(Self::Tc108),
            109u64 => Ok(Self::Tc109),
            110u64 => Ok(Self::Tc110),
            111u64 => Ok(Self::Tc111),
            112u64 => Ok(Self::Tc112),
            113u64 => Ok(Self::Tc113),
            114u64 => Ok(Self::Tc114),
            115u64 => Ok(Self::Tc115),
            116u64 => Ok(Self::Tc116),
            117u64 => Ok(Self::Tc117),
            118u64 => Ok(Self::Tc118),
            119u64 => Ok(Self::Tc119),
            120u64 => Ok(Self::Tc120),
            121u64 => Ok(Self::Tc121),
            122u64 => Ok(Self::Tc122),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Tc, value)),
        }
    }
}
impl TryFrom<u8> for TechnetiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for TechnetiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for TechnetiumIsotope {
    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 TechnetiumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Tc85 => write!(f, "Tc85"),
            Self::Tc86 => write!(f, "Tc86"),
            Self::Tc87 => write!(f, "Tc87"),
            Self::Tc88 => write!(f, "Tc88"),
            Self::Tc89 => write!(f, "Tc89"),
            Self::Tc90 => write!(f, "Tc90"),
            Self::Tc91 => write!(f, "Tc91"),
            Self::Tc92 => write!(f, "Tc92"),
            Self::Tc93 => write!(f, "Tc93"),
            Self::Tc94 => write!(f, "Tc94"),
            Self::Tc95 => write!(f, "Tc95"),
            Self::Tc96 => write!(f, "Tc96"),
            Self::Tc97 => write!(f, "Tc97"),
            Self::Tc98 => write!(f, "Tc98"),
            Self::Tc99 => write!(f, "Tc99"),
            Self::Tc100 => write!(f, "Tc100"),
            Self::Tc101 => write!(f, "Tc101"),
            Self::Tc102 => write!(f, "Tc102"),
            Self::Tc103 => write!(f, "Tc103"),
            Self::Tc104 => write!(f, "Tc104"),
            Self::Tc105 => write!(f, "Tc105"),
            Self::Tc106 => write!(f, "Tc106"),
            Self::Tc107 => write!(f, "Tc107"),
            Self::Tc108 => write!(f, "Tc108"),
            Self::Tc109 => write!(f, "Tc109"),
            Self::Tc110 => write!(f, "Tc110"),
            Self::Tc111 => write!(f, "Tc111"),
            Self::Tc112 => write!(f, "Tc112"),
            Self::Tc113 => write!(f, "Tc113"),
            Self::Tc114 => write!(f, "Tc114"),
            Self::Tc115 => write!(f, "Tc115"),
            Self::Tc116 => write!(f, "Tc116"),
            Self::Tc117 => write!(f, "Tc117"),
            Self::Tc118 => write!(f, "Tc118"),
            Self::Tc119 => write!(f, "Tc119"),
            Self::Tc120 => write!(f, "Tc120"),
            Self::Tc121 => write!(f, "Tc121"),
            Self::Tc122 => write!(f, "Tc122"),
        }
    }
}
#[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 TechnetiumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in TechnetiumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Tc, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in TechnetiumIsotope::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 TechnetiumIsotope::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 = TechnetiumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in TechnetiumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Tc(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in TechnetiumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Tc);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in TechnetiumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = TechnetiumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = TechnetiumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = TechnetiumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(TechnetiumIsotope::try_from(0_u16).is_err());
        assert!(TechnetiumIsotope::try_from(1000_u16).is_err());
        assert!(TechnetiumIsotope::try_from(0_u32).is_err());
        assert!(TechnetiumIsotope::try_from(1000_u32).is_err());
        assert!(TechnetiumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in TechnetiumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}