elements_rs 0.2.6

A comprehensive library for chemical elements and their isotopes with rich metadata
Documentation
//! Isotopes of the element Zinc
#[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 Zinc
pub enum ZincIsotope {
    /// Isotope Zn54 of Zinc
    Zn54,
    /// Isotope Zn55 of Zinc
    Zn55,
    /// Isotope Zn56 of Zinc
    Zn56,
    /// Isotope Zn57 of Zinc
    Zn57,
    /// Isotope Zn58 of Zinc
    Zn58,
    /// Isotope Zn59 of Zinc
    Zn59,
    /// Isotope Zn60 of Zinc
    Zn60,
    /// Isotope Zn61 of Zinc
    Zn61,
    /// Isotope Zn62 of Zinc
    Zn62,
    /// Isotope Zn63 of Zinc
    Zn63,
    /// Isotope Zn64 of Zinc
    Zn64,
    /// Isotope Zn65 of Zinc
    Zn65,
    /// Isotope Zn66 of Zinc
    Zn66,
    /// Isotope Zn67 of Zinc
    Zn67,
    /// Isotope Zn68 of Zinc
    Zn68,
    /// Isotope Zn69 of Zinc
    Zn69,
    /// Isotope Zn70 of Zinc
    Zn70,
    /// Isotope Zn71 of Zinc
    Zn71,
    /// Isotope Zn72 of Zinc
    Zn72,
    /// Isotope Zn73 of Zinc
    Zn73,
    /// Isotope Zn74 of Zinc
    Zn74,
    /// Isotope Zn75 of Zinc
    Zn75,
    /// Isotope Zn76 of Zinc
    Zn76,
    /// Isotope Zn77 of Zinc
    Zn77,
    /// Isotope Zn78 of Zinc
    Zn78,
    /// Isotope Zn79 of Zinc
    Zn79,
    /// Isotope Zn80 of Zinc
    Zn80,
    /// Isotope Zn81 of Zinc
    Zn81,
    /// Isotope Zn82 of Zinc
    Zn82,
    /// Isotope Zn83 of Zinc
    Zn83,
    /// Isotope Zn84 of Zinc
    Zn84,
    /// Isotope Zn85 of Zinc
    Zn85,
    /// Isotope Zn86 of Zinc
    Zn86,
}
impl super::RelativeAtomicMass for ZincIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Zn54 => 53.99204f64,
            Self::Zn55 => 54.98398f64,
            Self::Zn56 => 55.97254f64,
            Self::Zn57 => 56.96506f64,
            Self::Zn58 => 57.954591f64,
            Self::Zn59 => 58.94931266f64,
            Self::Zn60 => 59.9418421f64,
            Self::Zn61 => 60.939507f64,
            Self::Zn62 => 61.93433397f64,
            Self::Zn63 => 62.9332115f64,
            Self::Zn64 => 63.92914201f64,
            Self::Zn65 => 64.92924077f64,
            Self::Zn66 => 65.92603381f64,
            Self::Zn67 => 66.92712775f64,
            Self::Zn68 => 67.92484455f64,
            Self::Zn69 => 68.9265507f64,
            Self::Zn70 => 69.9253192f64,
            Self::Zn71 => 70.9277196f64,
            Self::Zn72 => 71.9268428f64,
            Self::Zn73 => 72.9295826f64,
            Self::Zn74 => 73.9294073f64,
            Self::Zn75 => 74.9328402f64,
            Self::Zn76 => 75.933115f64,
            Self::Zn77 => 76.9368872f64,
            Self::Zn78 => 77.9382892f64,
            Self::Zn79 => 78.9426381f64,
            Self::Zn80 => 79.9445529f64,
            Self::Zn81 => 80.9504026f64,
            Self::Zn82 => 81.95426f64,
            Self::Zn83 => 82.96056f64,
            Self::Zn84 => 83.96521f64,
            Self::Zn85 => 84.97226f64,
            Self::Zn86 => 85.978465f64,
        }
    }
}
impl super::ElementVariant for ZincIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Zn
    }
}
impl super::MassNumber for ZincIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Zn54 => 54u16,
            Self::Zn55 => 55u16,
            Self::Zn56 => 56u16,
            Self::Zn57 => 57u16,
            Self::Zn58 => 58u16,
            Self::Zn59 => 59u16,
            Self::Zn60 => 60u16,
            Self::Zn61 => 61u16,
            Self::Zn62 => 62u16,
            Self::Zn63 => 63u16,
            Self::Zn64 => 64u16,
            Self::Zn65 => 65u16,
            Self::Zn66 => 66u16,
            Self::Zn67 => 67u16,
            Self::Zn68 => 68u16,
            Self::Zn69 => 69u16,
            Self::Zn70 => 70u16,
            Self::Zn71 => 71u16,
            Self::Zn72 => 72u16,
            Self::Zn73 => 73u16,
            Self::Zn74 => 74u16,
            Self::Zn75 => 75u16,
            Self::Zn76 => 76u16,
            Self::Zn77 => 77u16,
            Self::Zn78 => 78u16,
            Self::Zn79 => 79u16,
            Self::Zn80 => 80u16,
            Self::Zn81 => 81u16,
            Self::Zn82 => 82u16,
            Self::Zn83 => 83u16,
            Self::Zn84 => 84u16,
            Self::Zn85 => 85u16,
            Self::Zn86 => 86u16,
        }
    }
}
impl super::IsotopicComposition for ZincIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Zn64 => Some(0.4917f64),
            Self::Zn66 => Some(0.2773f64),
            Self::Zn67 => Some(0.0404f64),
            Self::Zn68 => Some(0.1845f64),
            Self::Zn70 => Some(0.0061f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for ZincIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Zn64
    }
}
impl From<ZincIsotope> for crate::Isotope {
    fn from(isotope: ZincIsotope) -> Self {
        crate::Isotope::Zn(isotope)
    }
}
impl From<ZincIsotope> for crate::Element {
    fn from(_isotope: ZincIsotope) -> Self {
        crate::Element::Zn
    }
}
impl TryFrom<u64> for ZincIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            54u64 => Ok(Self::Zn54),
            55u64 => Ok(Self::Zn55),
            56u64 => Ok(Self::Zn56),
            57u64 => Ok(Self::Zn57),
            58u64 => Ok(Self::Zn58),
            59u64 => Ok(Self::Zn59),
            60u64 => Ok(Self::Zn60),
            61u64 => Ok(Self::Zn61),
            62u64 => Ok(Self::Zn62),
            63u64 => Ok(Self::Zn63),
            64u64 => Ok(Self::Zn64),
            65u64 => Ok(Self::Zn65),
            66u64 => Ok(Self::Zn66),
            67u64 => Ok(Self::Zn67),
            68u64 => Ok(Self::Zn68),
            69u64 => Ok(Self::Zn69),
            70u64 => Ok(Self::Zn70),
            71u64 => Ok(Self::Zn71),
            72u64 => Ok(Self::Zn72),
            73u64 => Ok(Self::Zn73),
            74u64 => Ok(Self::Zn74),
            75u64 => Ok(Self::Zn75),
            76u64 => Ok(Self::Zn76),
            77u64 => Ok(Self::Zn77),
            78u64 => Ok(Self::Zn78),
            79u64 => Ok(Self::Zn79),
            80u64 => Ok(Self::Zn80),
            81u64 => Ok(Self::Zn81),
            82u64 => Ok(Self::Zn82),
            83u64 => Ok(Self::Zn83),
            84u64 => Ok(Self::Zn84),
            85u64 => Ok(Self::Zn85),
            86u64 => Ok(Self::Zn86),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Zn, value)),
        }
    }
}
impl TryFrom<u8> for ZincIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for ZincIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for ZincIsotope {
    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 ZincIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Zn54 => write!(f, "Zn54"),
            Self::Zn55 => write!(f, "Zn55"),
            Self::Zn56 => write!(f, "Zn56"),
            Self::Zn57 => write!(f, "Zn57"),
            Self::Zn58 => write!(f, "Zn58"),
            Self::Zn59 => write!(f, "Zn59"),
            Self::Zn60 => write!(f, "Zn60"),
            Self::Zn61 => write!(f, "Zn61"),
            Self::Zn62 => write!(f, "Zn62"),
            Self::Zn63 => write!(f, "Zn63"),
            Self::Zn64 => write!(f, "Zn64"),
            Self::Zn65 => write!(f, "Zn65"),
            Self::Zn66 => write!(f, "Zn66"),
            Self::Zn67 => write!(f, "Zn67"),
            Self::Zn68 => write!(f, "Zn68"),
            Self::Zn69 => write!(f, "Zn69"),
            Self::Zn70 => write!(f, "Zn70"),
            Self::Zn71 => write!(f, "Zn71"),
            Self::Zn72 => write!(f, "Zn72"),
            Self::Zn73 => write!(f, "Zn73"),
            Self::Zn74 => write!(f, "Zn74"),
            Self::Zn75 => write!(f, "Zn75"),
            Self::Zn76 => write!(f, "Zn76"),
            Self::Zn77 => write!(f, "Zn77"),
            Self::Zn78 => write!(f, "Zn78"),
            Self::Zn79 => write!(f, "Zn79"),
            Self::Zn80 => write!(f, "Zn80"),
            Self::Zn81 => write!(f, "Zn81"),
            Self::Zn82 => write!(f, "Zn82"),
            Self::Zn83 => write!(f, "Zn83"),
            Self::Zn84 => write!(f, "Zn84"),
            Self::Zn85 => write!(f, "Zn85"),
            Self::Zn86 => write!(f, "Zn86"),
        }
    }
}
#[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 ZincIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in ZincIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Zn, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in ZincIsotope::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 ZincIsotope::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 = ZincIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in ZincIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Zn(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in ZincIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Zn);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in ZincIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = ZincIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = ZincIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = ZincIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(ZincIsotope::try_from(0_u16).is_err());
        assert!(ZincIsotope::try_from(1000_u16).is_err());
        assert!(ZincIsotope::try_from(0_u32).is_err());
        assert!(ZincIsotope::try_from(1000_u32).is_err());
        assert!(ZincIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in ZincIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}