elements_rs 0.2.6

A comprehensive library for chemical elements and their isotopes with rich metadata
Documentation
//! Isotopes of the element Curium
#[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 Curium
pub enum CuriumIsotope {
    /// Isotope Cm233 of Curium
    Cm233,
    /// Isotope Cm234 of Curium
    Cm234,
    /// Isotope Cm235 of Curium
    Cm235,
    /// Isotope Cm236 of Curium
    Cm236,
    /// Isotope Cm237 of Curium
    Cm237,
    /// Isotope Cm238 of Curium
    Cm238,
    /// Isotope Cm239 of Curium
    Cm239,
    /// Isotope Cm240 of Curium
    Cm240,
    /// Isotope Cm241 of Curium
    Cm241,
    /// Isotope Cm242 of Curium
    Cm242,
    /// Isotope Cm243 of Curium
    Cm243,
    /// Isotope Cm244 of Curium
    Cm244,
    /// Isotope Cm245 of Curium
    Cm245,
    /// Isotope Cm246 of Curium
    Cm246,
    /// Isotope Cm247 of Curium
    Cm247,
    /// Isotope Cm248 of Curium
    Cm248,
    /// Isotope Cm249 of Curium
    Cm249,
    /// Isotope Cm250 of Curium
    Cm250,
    /// Isotope Cm251 of Curium
    Cm251,
}
impl super::RelativeAtomicMass for CuriumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Cm233 => 233.05077f64,
            Self::Cm234 => 234.05016f64,
            Self::Cm235 => 235.05154f64,
            Self::Cm236 => 236.051374f64,
            Self::Cm237 => 237.052869f64,
            Self::Cm238 => 238.053081f64,
            Self::Cm239 => 239.05491f64,
            Self::Cm240 => 240.0555297f64,
            Self::Cm241 => 241.0576532f64,
            Self::Cm242 => 242.058836f64,
            Self::Cm243 => 243.0613893f64,
            Self::Cm244 => 244.0627528f64,
            Self::Cm245 => 245.0654915f64,
            Self::Cm246 => 246.0672238f64,
            Self::Cm247 => 247.0703541f64,
            Self::Cm248 => 248.0723499f64,
            Self::Cm249 => 249.0759548f64,
            Self::Cm250 => 250.078358f64,
            Self::Cm251 => 251.082286f64,
        }
    }
}
impl super::ElementVariant for CuriumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Cm
    }
}
impl super::MassNumber for CuriumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Cm233 => 233u16,
            Self::Cm234 => 234u16,
            Self::Cm235 => 235u16,
            Self::Cm236 => 236u16,
            Self::Cm237 => 237u16,
            Self::Cm238 => 238u16,
            Self::Cm239 => 239u16,
            Self::Cm240 => 240u16,
            Self::Cm241 => 241u16,
            Self::Cm242 => 242u16,
            Self::Cm243 => 243u16,
            Self::Cm244 => 244u16,
            Self::Cm245 => 245u16,
            Self::Cm246 => 246u16,
            Self::Cm247 => 247u16,
            Self::Cm248 => 248u16,
            Self::Cm249 => 249u16,
            Self::Cm250 => 250u16,
            Self::Cm251 => 251u16,
        }
    }
}
impl super::IsotopicComposition for CuriumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        None
    }
}
impl super::MostAbundantIsotope for CuriumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Cm251
    }
}
impl From<CuriumIsotope> for crate::Isotope {
    fn from(isotope: CuriumIsotope) -> Self {
        crate::Isotope::Cm(isotope)
    }
}
impl From<CuriumIsotope> for crate::Element {
    fn from(_isotope: CuriumIsotope) -> Self {
        crate::Element::Cm
    }
}
impl TryFrom<u64> for CuriumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            233u64 => Ok(Self::Cm233),
            234u64 => Ok(Self::Cm234),
            235u64 => Ok(Self::Cm235),
            236u64 => Ok(Self::Cm236),
            237u64 => Ok(Self::Cm237),
            238u64 => Ok(Self::Cm238),
            239u64 => Ok(Self::Cm239),
            240u64 => Ok(Self::Cm240),
            241u64 => Ok(Self::Cm241),
            242u64 => Ok(Self::Cm242),
            243u64 => Ok(Self::Cm243),
            244u64 => Ok(Self::Cm244),
            245u64 => Ok(Self::Cm245),
            246u64 => Ok(Self::Cm246),
            247u64 => Ok(Self::Cm247),
            248u64 => Ok(Self::Cm248),
            249u64 => Ok(Self::Cm249),
            250u64 => Ok(Self::Cm250),
            251u64 => Ok(Self::Cm251),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Cm, value)),
        }
    }
}
impl TryFrom<u8> for CuriumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for CuriumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for CuriumIsotope {
    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 CuriumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Cm233 => write!(f, "Cm233"),
            Self::Cm234 => write!(f, "Cm234"),
            Self::Cm235 => write!(f, "Cm235"),
            Self::Cm236 => write!(f, "Cm236"),
            Self::Cm237 => write!(f, "Cm237"),
            Self::Cm238 => write!(f, "Cm238"),
            Self::Cm239 => write!(f, "Cm239"),
            Self::Cm240 => write!(f, "Cm240"),
            Self::Cm241 => write!(f, "Cm241"),
            Self::Cm242 => write!(f, "Cm242"),
            Self::Cm243 => write!(f, "Cm243"),
            Self::Cm244 => write!(f, "Cm244"),
            Self::Cm245 => write!(f, "Cm245"),
            Self::Cm246 => write!(f, "Cm246"),
            Self::Cm247 => write!(f, "Cm247"),
            Self::Cm248 => write!(f, "Cm248"),
            Self::Cm249 => write!(f, "Cm249"),
            Self::Cm250 => write!(f, "Cm250"),
            Self::Cm251 => write!(f, "Cm251"),
        }
    }
}
#[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 CuriumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in CuriumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Cm, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in CuriumIsotope::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 CuriumIsotope::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 = CuriumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in CuriumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Cm(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in CuriumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Cm);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in CuriumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = CuriumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = CuriumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = CuriumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(CuriumIsotope::try_from(0_u16).is_err());
        assert!(CuriumIsotope::try_from(1000_u16).is_err());
        assert!(CuriumIsotope::try_from(0_u32).is_err());
        assert!(CuriumIsotope::try_from(1000_u32).is_err());
        assert!(CuriumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in CuriumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}