#[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))]
pub enum ThoriumIsotope {
Th208,
Th209,
Th210,
Th211,
Th212,
Th213,
Th214,
Th215,
Th216,
Th217,
Th218,
Th219,
Th220,
Th221,
Th222,
Th223,
Th224,
Th225,
Th226,
Th227,
Th228,
Th229,
Th230,
Th231,
Th232,
Th233,
Th234,
Th235,
Th236,
Th237,
Th238,
Th239,
}
impl super::RelativeAtomicMass for ThoriumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Th208 => 208.0179f64,
Self::Th209 => 209.017753f64,
Self::Th210 => 210.015094f64,
Self::Th211 => 211.014929f64,
Self::Th212 => 212.012988f64,
Self::Th213 => 213.013009f64,
Self::Th214 => 214.0115f64,
Self::Th215 => 215.0117248f64,
Self::Th216 => 216.011056f64,
Self::Th217 => 217.013117f64,
Self::Th218 => 218.013276f64,
Self::Th219 => 219.015537f64,
Self::Th220 => 220.015748f64,
Self::Th221 => 221.018184f64,
Self::Th222 => 222.018469f64,
Self::Th223 => 223.0208119f64,
Self::Th224 => 224.021464f64,
Self::Th225 => 225.0239514f64,
Self::Th226 => 226.0249034f64,
Self::Th227 => 227.0277042f64,
Self::Th228 => 228.0287413f64,
Self::Th229 => 229.0317627f64,
Self::Th230 => 230.0331341f64,
Self::Th231 => 231.0363046f64,
Self::Th232 => 232.0380558f64,
Self::Th233 => 233.0415823f64,
Self::Th234 => 234.0436014f64,
Self::Th235 => 235.047255f64,
Self::Th236 => 236.049657f64,
Self::Th237 => 237.053629f64,
Self::Th238 => 238.0565f64,
Self::Th239 => 239.060655f64,
}
}
}
impl super::ElementVariant for ThoriumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Th
}
}
impl super::MassNumber for ThoriumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Th208 => 208u16,
Self::Th209 => 209u16,
Self::Th210 => 210u16,
Self::Th211 => 211u16,
Self::Th212 => 212u16,
Self::Th213 => 213u16,
Self::Th214 => 214u16,
Self::Th215 => 215u16,
Self::Th216 => 216u16,
Self::Th217 => 217u16,
Self::Th218 => 218u16,
Self::Th219 => 219u16,
Self::Th220 => 220u16,
Self::Th221 => 221u16,
Self::Th222 => 222u16,
Self::Th223 => 223u16,
Self::Th224 => 224u16,
Self::Th225 => 225u16,
Self::Th226 => 226u16,
Self::Th227 => 227u16,
Self::Th228 => 228u16,
Self::Th229 => 229u16,
Self::Th230 => 230u16,
Self::Th231 => 231u16,
Self::Th232 => 232u16,
Self::Th233 => 233u16,
Self::Th234 => 234u16,
Self::Th235 => 235u16,
Self::Th236 => 236u16,
Self::Th237 => 237u16,
Self::Th238 => 238u16,
Self::Th239 => 239u16,
}
}
}
impl super::IsotopicComposition for ThoriumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Th232 => Some(1f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for ThoriumIsotope {
fn most_abundant_isotope() -> Self {
Self::Th232
}
}
impl From<ThoriumIsotope> for crate::Isotope {
fn from(isotope: ThoriumIsotope) -> Self {
crate::Isotope::Th(isotope)
}
}
impl From<ThoriumIsotope> for crate::Element {
fn from(_isotope: ThoriumIsotope) -> Self {
crate::Element::Th
}
}
impl TryFrom<u64> for ThoriumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
208u64 => Ok(Self::Th208),
209u64 => Ok(Self::Th209),
210u64 => Ok(Self::Th210),
211u64 => Ok(Self::Th211),
212u64 => Ok(Self::Th212),
213u64 => Ok(Self::Th213),
214u64 => Ok(Self::Th214),
215u64 => Ok(Self::Th215),
216u64 => Ok(Self::Th216),
217u64 => Ok(Self::Th217),
218u64 => Ok(Self::Th218),
219u64 => Ok(Self::Th219),
220u64 => Ok(Self::Th220),
221u64 => Ok(Self::Th221),
222u64 => Ok(Self::Th222),
223u64 => Ok(Self::Th223),
224u64 => Ok(Self::Th224),
225u64 => Ok(Self::Th225),
226u64 => Ok(Self::Th226),
227u64 => Ok(Self::Th227),
228u64 => Ok(Self::Th228),
229u64 => Ok(Self::Th229),
230u64 => Ok(Self::Th230),
231u64 => Ok(Self::Th231),
232u64 => Ok(Self::Th232),
233u64 => Ok(Self::Th233),
234u64 => Ok(Self::Th234),
235u64 => Ok(Self::Th235),
236u64 => Ok(Self::Th236),
237u64 => Ok(Self::Th237),
238u64 => Ok(Self::Th238),
239u64 => Ok(Self::Th239),
_ => Err(crate::errors::Error::Isotope(crate::Element::Th, value)),
}
}
}
impl TryFrom<u8> for ThoriumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for ThoriumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for ThoriumIsotope {
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 ThoriumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Th208 => write!(f, "Th208"),
Self::Th209 => write!(f, "Th209"),
Self::Th210 => write!(f, "Th210"),
Self::Th211 => write!(f, "Th211"),
Self::Th212 => write!(f, "Th212"),
Self::Th213 => write!(f, "Th213"),
Self::Th214 => write!(f, "Th214"),
Self::Th215 => write!(f, "Th215"),
Self::Th216 => write!(f, "Th216"),
Self::Th217 => write!(f, "Th217"),
Self::Th218 => write!(f, "Th218"),
Self::Th219 => write!(f, "Th219"),
Self::Th220 => write!(f, "Th220"),
Self::Th221 => write!(f, "Th221"),
Self::Th222 => write!(f, "Th222"),
Self::Th223 => write!(f, "Th223"),
Self::Th224 => write!(f, "Th224"),
Self::Th225 => write!(f, "Th225"),
Self::Th226 => write!(f, "Th226"),
Self::Th227 => write!(f, "Th227"),
Self::Th228 => write!(f, "Th228"),
Self::Th229 => write!(f, "Th229"),
Self::Th230 => write!(f, "Th230"),
Self::Th231 => write!(f, "Th231"),
Self::Th232 => write!(f, "Th232"),
Self::Th233 => write!(f, "Th233"),
Self::Th234 => write!(f, "Th234"),
Self::Th235 => write!(f, "Th235"),
Self::Th236 => write!(f, "Th236"),
Self::Th237 => write!(f, "Th237"),
Self::Th238 => write!(f, "Th238"),
Self::Th239 => write!(f, "Th239"),
}
}
}
#[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 ThoriumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in ThoriumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Th, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in ThoriumIsotope::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 ThoriumIsotope::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 = ThoriumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in ThoriumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Th(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in ThoriumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Th);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in ThoriumIsotope::iter() {
let mass = isotope.mass_number();
let iso = ThoriumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = ThoriumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = ThoriumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(ThoriumIsotope::try_from(0_u16).is_err());
assert!(ThoriumIsotope::try_from(1000_u16).is_err());
assert!(ThoriumIsotope::try_from(0_u32).is_err());
assert!(ThoriumIsotope::try_from(1000_u32).is_err());
assert!(ThoriumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in ThoriumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}