elements_rs 0.2.5

A comprehensive library for chemical elements and their isotopes with rich metadata
Documentation
//! Isotopes of the element Lawrencium
#[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 Lawrencium
pub enum LawrenciumIsotope {
    /// Isotope Lr251 of Lawrencium
    Lr251,
    /// Isotope Lr252 of Lawrencium
    Lr252,
    /// Isotope Lr253 of Lawrencium
    Lr253,
    /// Isotope Lr254 of Lawrencium
    Lr254,
    /// Isotope Lr255 of Lawrencium
    Lr255,
    /// Isotope Lr256 of Lawrencium
    Lr256,
    /// Isotope Lr257 of Lawrencium
    Lr257,
    /// Isotope Lr258 of Lawrencium
    Lr258,
    /// Isotope Lr259 of Lawrencium
    Lr259,
    /// Isotope Lr260 of Lawrencium
    Lr260,
    /// Isotope Lr261 of Lawrencium
    Lr261,
    /// Isotope Lr262 of Lawrencium
    Lr262,
    /// Isotope Lr264 of Lawrencium
    Lr264,
    /// Isotope Lr266 of Lawrencium
    Lr266,
}
impl super::RelativeAtomicMass for LawrenciumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Lr251 => 251.094289f64,
            Self::Lr252 => 252.09526f64,
            Self::Lr253 => 253.09509f64,
            Self::Lr254 => 254.09648f64,
            Self::Lr255 => 255.096562f64,
            Self::Lr256 => 256.098494f64,
            Self::Lr257 => 257.099418f64,
            Self::Lr258 => 258.10176f64,
            Self::Lr259 => 259.102902f64,
            Self::Lr260 => 260.1055f64,
            Self::Lr261 => 261.10688f64,
            Self::Lr262 => 262.10961f64,
            Self::Lr264 => 264.1142f64,
            Self::Lr266 => 266.11983f64,
        }
    }
}
impl super::ElementVariant for LawrenciumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Lr
    }
}
impl super::MassNumber for LawrenciumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Lr251 => 251u16,
            Self::Lr252 => 252u16,
            Self::Lr253 => 253u16,
            Self::Lr254 => 254u16,
            Self::Lr255 => 255u16,
            Self::Lr256 => 256u16,
            Self::Lr257 => 257u16,
            Self::Lr258 => 258u16,
            Self::Lr259 => 259u16,
            Self::Lr260 => 260u16,
            Self::Lr261 => 261u16,
            Self::Lr262 => 262u16,
            Self::Lr264 => 264u16,
            Self::Lr266 => 266u16,
        }
    }
}
impl super::IsotopicComposition for LawrenciumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        None
    }
}
impl super::MostAbundantIsotope for LawrenciumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Lr266
    }
}
impl From<LawrenciumIsotope> for crate::Isotope {
    fn from(isotope: LawrenciumIsotope) -> Self {
        crate::Isotope::Lr(isotope)
    }
}
impl From<LawrenciumIsotope> for crate::Element {
    fn from(_isotope: LawrenciumIsotope) -> Self {
        crate::Element::Lr
    }
}
impl TryFrom<u64> for LawrenciumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            251u64 => Ok(Self::Lr251),
            252u64 => Ok(Self::Lr252),
            253u64 => Ok(Self::Lr253),
            254u64 => Ok(Self::Lr254),
            255u64 => Ok(Self::Lr255),
            256u64 => Ok(Self::Lr256),
            257u64 => Ok(Self::Lr257),
            258u64 => Ok(Self::Lr258),
            259u64 => Ok(Self::Lr259),
            260u64 => Ok(Self::Lr260),
            261u64 => Ok(Self::Lr261),
            262u64 => Ok(Self::Lr262),
            264u64 => Ok(Self::Lr264),
            266u64 => Ok(Self::Lr266),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Lr, value)),
        }
    }
}
impl TryFrom<u8> for LawrenciumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for LawrenciumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for LawrenciumIsotope {
    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 LawrenciumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Lr251 => write!(f, "Lr251"),
            Self::Lr252 => write!(f, "Lr252"),
            Self::Lr253 => write!(f, "Lr253"),
            Self::Lr254 => write!(f, "Lr254"),
            Self::Lr255 => write!(f, "Lr255"),
            Self::Lr256 => write!(f, "Lr256"),
            Self::Lr257 => write!(f, "Lr257"),
            Self::Lr258 => write!(f, "Lr258"),
            Self::Lr259 => write!(f, "Lr259"),
            Self::Lr260 => write!(f, "Lr260"),
            Self::Lr261 => write!(f, "Lr261"),
            Self::Lr262 => write!(f, "Lr262"),
            Self::Lr264 => write!(f, "Lr264"),
            Self::Lr266 => write!(f, "Lr266"),
        }
    }
}
#[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 LawrenciumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in LawrenciumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Lr, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in LawrenciumIsotope::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 LawrenciumIsotope::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 = LawrenciumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in LawrenciumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Lr(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in LawrenciumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Lr);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in LawrenciumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = LawrenciumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = LawrenciumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = LawrenciumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(LawrenciumIsotope::try_from(0_u16).is_err());
        assert!(LawrenciumIsotope::try_from(1000_u16).is_err());
        assert!(LawrenciumIsotope::try_from(0_u32).is_err());
        assert!(LawrenciumIsotope::try_from(1000_u32).is_err());
        assert!(LawrenciumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in LawrenciumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}