elements_rs 0.2.6

A comprehensive library for chemical elements and their isotopes with rich metadata
Documentation
//! Isotopes of the element Nickel
#[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 Nickel
pub enum NickelIsotope {
    /// Isotope Ni48 of Nickel
    Ni48,
    /// Isotope Ni49 of Nickel
    Ni49,
    /// Isotope Ni50 of Nickel
    Ni50,
    /// Isotope Ni51 of Nickel
    Ni51,
    /// Isotope Ni52 of Nickel
    Ni52,
    /// Isotope Ni53 of Nickel
    Ni53,
    /// Isotope Ni54 of Nickel
    Ni54,
    /// Isotope Ni55 of Nickel
    Ni55,
    /// Isotope Ni56 of Nickel
    Ni56,
    /// Isotope Ni57 of Nickel
    Ni57,
    /// Isotope Ni58 of Nickel
    Ni58,
    /// Isotope Ni59 of Nickel
    Ni59,
    /// Isotope Ni60 of Nickel
    Ni60,
    /// Isotope Ni61 of Nickel
    Ni61,
    /// Isotope Ni62 of Nickel
    Ni62,
    /// Isotope Ni63 of Nickel
    Ni63,
    /// Isotope Ni64 of Nickel
    Ni64,
    /// Isotope Ni65 of Nickel
    Ni65,
    /// Isotope Ni66 of Nickel
    Ni66,
    /// Isotope Ni67 of Nickel
    Ni67,
    /// Isotope Ni68 of Nickel
    Ni68,
    /// Isotope Ni69 of Nickel
    Ni69,
    /// Isotope Ni70 of Nickel
    Ni70,
    /// Isotope Ni71 of Nickel
    Ni71,
    /// Isotope Ni72 of Nickel
    Ni72,
    /// Isotope Ni73 of Nickel
    Ni73,
    /// Isotope Ni74 of Nickel
    Ni74,
    /// Isotope Ni75 of Nickel
    Ni75,
    /// Isotope Ni76 of Nickel
    Ni76,
    /// Isotope Ni77 of Nickel
    Ni77,
    /// Isotope Ni78 of Nickel
    Ni78,
    /// Isotope Ni79 of Nickel
    Ni79,
    /// Isotope Ni80 of Nickel
    Ni80,
    /// Isotope Ni81 of Nickel
    Ni81,
    /// Isotope Ni82 of Nickel
    Ni82,
}
impl super::RelativeAtomicMass for NickelIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Ni48 => 48.01769f64,
            Self::Ni49 => 49.0077f64,
            Self::Ni50 => 49.99474f64,
            Self::Ni51 => 50.98611f64,
            Self::Ni52 => 51.9748f64,
            Self::Ni53 => 52.96819f64,
            Self::Ni54 => 53.957892f64,
            Self::Ni55 => 54.95133063f64,
            Self::Ni56 => 55.94212855f64,
            Self::Ni57 => 56.93979218f64,
            Self::Ni58 => 57.93534241f64,
            Self::Ni59 => 58.9343462f64,
            Self::Ni60 => 59.93078588f64,
            Self::Ni61 => 60.93105557f64,
            Self::Ni62 => 61.92834537f64,
            Self::Ni63 => 62.92966963f64,
            Self::Ni64 => 63.92796682f64,
            Self::Ni65 => 64.93008517f64,
            Self::Ni66 => 65.9291393f64,
            Self::Ni67 => 66.9315694f64,
            Self::Ni68 => 67.9318688f64,
            Self::Ni69 => 68.9356103f64,
            Self::Ni70 => 69.9364313f64,
            Self::Ni71 => 70.940519f64,
            Self::Ni72 => 71.9417859f64,
            Self::Ni73 => 72.9462067f64,
            Self::Ni74 => 73.94798f64,
            Self::Ni75 => 74.9525f64,
            Self::Ni76 => 75.95533f64,
            Self::Ni77 => 76.96055f64,
            Self::Ni78 => 77.96336f64,
            Self::Ni79 => 78.97025f64,
            Self::Ni80 => 79.975051f64,
            Self::Ni81 => 80.982727f64,
            Self::Ni82 => 81.988492f64,
        }
    }
}
impl super::ElementVariant for NickelIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Ni
    }
}
impl super::MassNumber for NickelIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Ni48 => 48u16,
            Self::Ni49 => 49u16,
            Self::Ni50 => 50u16,
            Self::Ni51 => 51u16,
            Self::Ni52 => 52u16,
            Self::Ni53 => 53u16,
            Self::Ni54 => 54u16,
            Self::Ni55 => 55u16,
            Self::Ni56 => 56u16,
            Self::Ni57 => 57u16,
            Self::Ni58 => 58u16,
            Self::Ni59 => 59u16,
            Self::Ni60 => 60u16,
            Self::Ni61 => 61u16,
            Self::Ni62 => 62u16,
            Self::Ni63 => 63u16,
            Self::Ni64 => 64u16,
            Self::Ni65 => 65u16,
            Self::Ni66 => 66u16,
            Self::Ni67 => 67u16,
            Self::Ni68 => 68u16,
            Self::Ni69 => 69u16,
            Self::Ni70 => 70u16,
            Self::Ni71 => 71u16,
            Self::Ni72 => 72u16,
            Self::Ni73 => 73u16,
            Self::Ni74 => 74u16,
            Self::Ni75 => 75u16,
            Self::Ni76 => 76u16,
            Self::Ni77 => 77u16,
            Self::Ni78 => 78u16,
            Self::Ni79 => 79u16,
            Self::Ni80 => 80u16,
            Self::Ni81 => 81u16,
            Self::Ni82 => 82u16,
        }
    }
}
impl super::IsotopicComposition for NickelIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Ni58 => Some(0.68077f64),
            Self::Ni60 => Some(0.26223f64),
            Self::Ni61 => Some(0.011399f64),
            Self::Ni62 => Some(0.036346f64),
            Self::Ni64 => Some(0.009255f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for NickelIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Ni58
    }
}
impl From<NickelIsotope> for crate::Isotope {
    fn from(isotope: NickelIsotope) -> Self {
        crate::Isotope::Ni(isotope)
    }
}
impl From<NickelIsotope> for crate::Element {
    fn from(_isotope: NickelIsotope) -> Self {
        crate::Element::Ni
    }
}
impl TryFrom<u64> for NickelIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            48u64 => Ok(Self::Ni48),
            49u64 => Ok(Self::Ni49),
            50u64 => Ok(Self::Ni50),
            51u64 => Ok(Self::Ni51),
            52u64 => Ok(Self::Ni52),
            53u64 => Ok(Self::Ni53),
            54u64 => Ok(Self::Ni54),
            55u64 => Ok(Self::Ni55),
            56u64 => Ok(Self::Ni56),
            57u64 => Ok(Self::Ni57),
            58u64 => Ok(Self::Ni58),
            59u64 => Ok(Self::Ni59),
            60u64 => Ok(Self::Ni60),
            61u64 => Ok(Self::Ni61),
            62u64 => Ok(Self::Ni62),
            63u64 => Ok(Self::Ni63),
            64u64 => Ok(Self::Ni64),
            65u64 => Ok(Self::Ni65),
            66u64 => Ok(Self::Ni66),
            67u64 => Ok(Self::Ni67),
            68u64 => Ok(Self::Ni68),
            69u64 => Ok(Self::Ni69),
            70u64 => Ok(Self::Ni70),
            71u64 => Ok(Self::Ni71),
            72u64 => Ok(Self::Ni72),
            73u64 => Ok(Self::Ni73),
            74u64 => Ok(Self::Ni74),
            75u64 => Ok(Self::Ni75),
            76u64 => Ok(Self::Ni76),
            77u64 => Ok(Self::Ni77),
            78u64 => Ok(Self::Ni78),
            79u64 => Ok(Self::Ni79),
            80u64 => Ok(Self::Ni80),
            81u64 => Ok(Self::Ni81),
            82u64 => Ok(Self::Ni82),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Ni, value)),
        }
    }
}
impl TryFrom<u8> for NickelIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for NickelIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for NickelIsotope {
    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 NickelIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Ni48 => write!(f, "Ni48"),
            Self::Ni49 => write!(f, "Ni49"),
            Self::Ni50 => write!(f, "Ni50"),
            Self::Ni51 => write!(f, "Ni51"),
            Self::Ni52 => write!(f, "Ni52"),
            Self::Ni53 => write!(f, "Ni53"),
            Self::Ni54 => write!(f, "Ni54"),
            Self::Ni55 => write!(f, "Ni55"),
            Self::Ni56 => write!(f, "Ni56"),
            Self::Ni57 => write!(f, "Ni57"),
            Self::Ni58 => write!(f, "Ni58"),
            Self::Ni59 => write!(f, "Ni59"),
            Self::Ni60 => write!(f, "Ni60"),
            Self::Ni61 => write!(f, "Ni61"),
            Self::Ni62 => write!(f, "Ni62"),
            Self::Ni63 => write!(f, "Ni63"),
            Self::Ni64 => write!(f, "Ni64"),
            Self::Ni65 => write!(f, "Ni65"),
            Self::Ni66 => write!(f, "Ni66"),
            Self::Ni67 => write!(f, "Ni67"),
            Self::Ni68 => write!(f, "Ni68"),
            Self::Ni69 => write!(f, "Ni69"),
            Self::Ni70 => write!(f, "Ni70"),
            Self::Ni71 => write!(f, "Ni71"),
            Self::Ni72 => write!(f, "Ni72"),
            Self::Ni73 => write!(f, "Ni73"),
            Self::Ni74 => write!(f, "Ni74"),
            Self::Ni75 => write!(f, "Ni75"),
            Self::Ni76 => write!(f, "Ni76"),
            Self::Ni77 => write!(f, "Ni77"),
            Self::Ni78 => write!(f, "Ni78"),
            Self::Ni79 => write!(f, "Ni79"),
            Self::Ni80 => write!(f, "Ni80"),
            Self::Ni81 => write!(f, "Ni81"),
            Self::Ni82 => write!(f, "Ni82"),
        }
    }
}
#[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 NickelIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in NickelIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Ni, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in NickelIsotope::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 NickelIsotope::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 = NickelIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in NickelIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Ni(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in NickelIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Ni);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in NickelIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = NickelIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = NickelIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = NickelIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(NickelIsotope::try_from(0_u16).is_err());
        assert!(NickelIsotope::try_from(1000_u16).is_err());
        assert!(NickelIsotope::try_from(0_u32).is_err());
        assert!(NickelIsotope::try_from(1000_u32).is_err());
        assert!(NickelIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in NickelIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}