elements_rs/isotopes/
nobelium.rs

1//! Isotopes of the element Nobelium
2#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, strum :: EnumIter)]
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4/// Isotopes of the element Nobelium
5pub enum NobeliumIsotope {
6    /// Isotope No248 of Nobelium
7    No248,
8    /// Isotope No249 of Nobelium
9    No249,
10    /// Isotope No250 of Nobelium
11    No250,
12    /// Isotope No251 of Nobelium
13    No251,
14    /// Isotope No252 of Nobelium
15    No252,
16    /// Isotope No253 of Nobelium
17    No253,
18    /// Isotope No254 of Nobelium
19    No254,
20    /// Isotope No255 of Nobelium
21    No255,
22    /// Isotope No256 of Nobelium
23    No256,
24    /// Isotope No257 of Nobelium
25    No257,
26    /// Isotope No258 of Nobelium
27    No258,
28    /// Isotope No259 of Nobelium
29    No259,
30    /// Isotope No260 of Nobelium
31    No260,
32    /// Isotope No261 of Nobelium
33    No261,
34    /// Isotope No262 of Nobelium
35    No262,
36    /// Isotope No263 of Nobelium
37    No263,
38    /// Isotope No264 of Nobelium
39    No264,
40}
41impl super::RelativeAtomicMass for NobeliumIsotope {
42    #[inline]
43    fn relative_atomic_mass(&self) -> f64 {
44        match self {
45            Self::No248 => 248.08655f64,
46            Self::No249 => 249.0878f64,
47            Self::No250 => 250.08756f64,
48            Self::No251 => 251.08894f64,
49            Self::No252 => 252.088967f64,
50            Self::No253 => 253.0905641f64,
51            Self::No254 => 254.090956f64,
52            Self::No255 => 255.093191f64,
53            Self::No256 => 256.0942829f64,
54            Self::No257 => 257.0968878f64,
55            Self::No258 => 258.09821f64,
56            Self::No259 => 259.10103f64,
57            Self::No260 => 260.10264f64,
58            Self::No261 => 261.1057f64,
59            Self::No262 => 262.10746f64,
60            Self::No263 => 263.11071f64,
61            Self::No264 => 264.11273f64,
62        }
63    }
64}
65impl super::ElementVariant for NobeliumIsotope {
66    #[inline]
67    fn element(&self) -> crate::Element {
68        crate::Element::No
69    }
70}
71impl super::MassNumber for NobeliumIsotope {
72    #[inline]
73    fn mass_number(&self) -> u16 {
74        match self {
75            Self::No248 => 248u16,
76            Self::No249 => 249u16,
77            Self::No250 => 250u16,
78            Self::No251 => 251u16,
79            Self::No252 => 252u16,
80            Self::No253 => 253u16,
81            Self::No254 => 254u16,
82            Self::No255 => 255u16,
83            Self::No256 => 256u16,
84            Self::No257 => 257u16,
85            Self::No258 => 258u16,
86            Self::No259 => 259u16,
87            Self::No260 => 260u16,
88            Self::No261 => 261u16,
89            Self::No262 => 262u16,
90            Self::No263 => 263u16,
91            Self::No264 => 264u16,
92        }
93    }
94}
95impl super::IsotopicComposition for NobeliumIsotope {
96    #[inline]
97    fn isotopic_composition(&self) -> Option<f64> {
98        None
99    }
100}
101impl super::MostAbundantIsotope for NobeliumIsotope {
102    fn most_abundant_isotope() -> Self {
103        Self::No264
104    }
105}
106impl From<NobeliumIsotope> for crate::Isotope {
107    fn from(isotope: NobeliumIsotope) -> Self {
108        crate::Isotope::No(isotope)
109    }
110}
111impl From<NobeliumIsotope> for crate::Element {
112    fn from(_isotope: NobeliumIsotope) -> Self {
113        crate::Element::No
114    }
115}
116impl TryFrom<u64> for NobeliumIsotope {
117    type Error = crate::errors::Error;
118    fn try_from(value: u64) -> Result<Self, Self::Error> {
119        match value {
120            248u64 => Ok(Self::No248),
121            249u64 => Ok(Self::No249),
122            250u64 => Ok(Self::No250),
123            251u64 => Ok(Self::No251),
124            252u64 => Ok(Self::No252),
125            253u64 => Ok(Self::No253),
126            254u64 => Ok(Self::No254),
127            255u64 => Ok(Self::No255),
128            256u64 => Ok(Self::No256),
129            257u64 => Ok(Self::No257),
130            258u64 => Ok(Self::No258),
131            259u64 => Ok(Self::No259),
132            260u64 => Ok(Self::No260),
133            261u64 => Ok(Self::No261),
134            262u64 => Ok(Self::No262),
135            263u64 => Ok(Self::No263),
136            264u64 => Ok(Self::No264),
137            _ => Err(crate::errors::Error::Isotope(crate::Element::No, value)),
138        }
139    }
140}
141impl TryFrom<u8> for NobeliumIsotope {
142    type Error = crate::errors::Error;
143    fn try_from(value: u8) -> Result<Self, Self::Error> {
144        Self::try_from(u64::from(value))
145    }
146}
147impl TryFrom<u16> for NobeliumIsotope {
148    type Error = crate::errors::Error;
149    fn try_from(value: u16) -> Result<Self, Self::Error> {
150        Self::try_from(u64::from(value))
151    }
152}
153impl TryFrom<u32> for NobeliumIsotope {
154    type Error = crate::errors::Error;
155    fn try_from(value: u32) -> Result<Self, Self::Error> {
156        Self::try_from(u64::from(value))
157    }
158}
159impl core::fmt::Display for NobeliumIsotope {
160    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
161        match self {
162            Self::No248 => write!(f, "No248"),
163            Self::No249 => write!(f, "No249"),
164            Self::No250 => write!(f, "No250"),
165            Self::No251 => write!(f, "No251"),
166            Self::No252 => write!(f, "No252"),
167            Self::No253 => write!(f, "No253"),
168            Self::No254 => write!(f, "No254"),
169            Self::No255 => write!(f, "No255"),
170            Self::No256 => write!(f, "No256"),
171            Self::No257 => write!(f, "No257"),
172            Self::No258 => write!(f, "No258"),
173            Self::No259 => write!(f, "No259"),
174            Self::No260 => write!(f, "No260"),
175            Self::No261 => write!(f, "No261"),
176            Self::No262 => write!(f, "No262"),
177            Self::No263 => write!(f, "No263"),
178            Self::No264 => write!(f, "No264"),
179        }
180    }
181}
182#[cfg(test)]
183mod tests {
184    use strum::IntoEnumIterator;
185
186    use super::*;
187    use crate::isotopes::{
188        ElementVariant, IsotopicComposition, MassNumber, MostAbundantIsotope, RelativeAtomicMass,
189    };
190    #[test]
191    fn test_relative_atomic_mass() {
192        for isotope in NobeliumIsotope::iter() {
193            let mass = isotope.relative_atomic_mass();
194            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
195        }
196    }
197    #[test]
198    fn test_element() {
199        for isotope in NobeliumIsotope::iter() {
200            let element = isotope.element();
201            assert_eq!(element, crate::Element::No, "Element should be correct for {isotope:?}");
202        }
203    }
204    #[test]
205    fn test_mass_number() {
206        for isotope in NobeliumIsotope::iter() {
207            let mass_number = isotope.mass_number();
208            assert!(
209                mass_number > 0 && mass_number < 300,
210                "Mass number should be reasonable for {isotope:?}"
211            );
212        }
213    }
214    #[test]
215    fn test_isotopic_composition() {
216        for isotope in NobeliumIsotope::iter() {
217            let comp = isotope.isotopic_composition();
218            if let Some(c) = comp {
219                assert!(
220                    (0.0..=1.0).contains(&c),
221                    "Composition should be between 0 and 1 for {isotope:?}"
222                );
223            }
224        }
225    }
226    #[test]
227    fn test_most_abundant() {
228        let most_abundant = NobeliumIsotope::most_abundant_isotope();
229        let _ = most_abundant.relative_atomic_mass();
230    }
231    #[test]
232    fn test_from_isotope() {
233        for isotope in NobeliumIsotope::iter() {
234            let iso: crate::Isotope = isotope.into();
235            match iso {
236                crate::Isotope::No(i) => assert_eq!(i, isotope),
237                _ => panic!("Wrong isotope type"),
238            }
239        }
240    }
241    #[test]
242    fn test_from_element() {
243        for isotope in NobeliumIsotope::iter() {
244            let elem: crate::Element = isotope.into();
245            assert_eq!(elem, crate::Element::No);
246        }
247    }
248    #[test]
249    fn test_try_from_mass_number() {
250        for isotope in NobeliumIsotope::iter() {
251            let mass = isotope.mass_number();
252            let iso = NobeliumIsotope::try_from(mass).unwrap();
253            assert_eq!(iso, isotope);
254            let iso_u32 = NobeliumIsotope::try_from(u32::from(mass)).unwrap();
255            assert_eq!(iso_u32, isotope);
256            if let Ok(mass_u8) = u8::try_from(mass) {
257                let iso_u8 = NobeliumIsotope::try_from(mass_u8).unwrap();
258                assert_eq!(iso_u8, isotope);
259            }
260        }
261        assert!(NobeliumIsotope::try_from(0_u16).is_err());
262        assert!(NobeliumIsotope::try_from(1000_u16).is_err());
263        assert!(NobeliumIsotope::try_from(0_u32).is_err());
264        assert!(NobeliumIsotope::try_from(1000_u32).is_err());
265        assert!(NobeliumIsotope::try_from(0_u8).is_err());
266    }
267    #[test]
268    fn test_display() {
269        for isotope in NobeliumIsotope::iter() {
270            let s = alloc::format!("{isotope}");
271            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
272        }
273    }
274}