elements_rs 0.2.5

A comprehensive library for chemical elements and their isotopes with rich metadata
Documentation
//! Isotopes of the element Flerovium
#[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))]
/// Isotopes of the element Flerovium
pub enum FleroviumIsotope {
    /// Isotope Fl284 of Flerovium
    Fl284,
    /// Isotope Fl285 of Flerovium
    Fl285,
    /// Isotope Fl286 of Flerovium
    Fl286,
    /// Isotope Fl287 of Flerovium
    Fl287,
    /// Isotope Fl288 of Flerovium
    Fl288,
    /// Isotope Fl289 of Flerovium
    Fl289,
    /// Isotope Fl290 of Flerovium
    Fl290,
}
impl super::RelativeAtomicMass for FleroviumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Fl284 => 284.181192f64,
            Self::Fl285 => 285.18364f64,
            Self::Fl286 => 286.18423f64,
            Self::Fl287 => 287.18678f64,
            Self::Fl288 => 288.18757f64,
            Self::Fl289 => 289.19042f64,
            Self::Fl290 => 290.191875f64,
        }
    }
}
impl super::ElementVariant for FleroviumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Fl
    }
}
impl super::MassNumber for FleroviumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Fl284 => 284u16,
            Self::Fl285 => 285u16,
            Self::Fl286 => 286u16,
            Self::Fl287 => 287u16,
            Self::Fl288 => 288u16,
            Self::Fl289 => 289u16,
            Self::Fl290 => 290u16,
        }
    }
}
impl super::IsotopicComposition for FleroviumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        None
    }
}
impl super::MostAbundantIsotope for FleroviumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Fl290
    }
}
impl From<FleroviumIsotope> for crate::Isotope {
    fn from(isotope: FleroviumIsotope) -> Self {
        crate::Isotope::Fl(isotope)
    }
}
impl From<FleroviumIsotope> for crate::Element {
    fn from(_isotope: FleroviumIsotope) -> Self {
        crate::Element::Fl
    }
}
impl TryFrom<u64> for FleroviumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            284u64 => Ok(Self::Fl284),
            285u64 => Ok(Self::Fl285),
            286u64 => Ok(Self::Fl286),
            287u64 => Ok(Self::Fl287),
            288u64 => Ok(Self::Fl288),
            289u64 => Ok(Self::Fl289),
            290u64 => Ok(Self::Fl290),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Fl, value)),
        }
    }
}
impl TryFrom<u8> for FleroviumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for FleroviumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for FleroviumIsotope {
    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 FleroviumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Fl284 => write!(f, "Fl284"),
            Self::Fl285 => write!(f, "Fl285"),
            Self::Fl286 => write!(f, "Fl286"),
            Self::Fl287 => write!(f, "Fl287"),
            Self::Fl288 => write!(f, "Fl288"),
            Self::Fl289 => write!(f, "Fl289"),
            Self::Fl290 => write!(f, "Fl290"),
        }
    }
}
#[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 FleroviumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in FleroviumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Fl, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in FleroviumIsotope::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 FleroviumIsotope::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 = FleroviumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in FleroviumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Fl(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in FleroviumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Fl);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in FleroviumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = FleroviumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = FleroviumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = FleroviumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(FleroviumIsotope::try_from(0_u16).is_err());
        assert!(FleroviumIsotope::try_from(1000_u16).is_err());
        assert!(FleroviumIsotope::try_from(0_u32).is_err());
        assert!(FleroviumIsotope::try_from(1000_u32).is_err());
        assert!(FleroviumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in FleroviumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}