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