elements_rs 0.2.6

A comprehensive library for chemical elements and their isotopes with rich metadata
Documentation
//! Submodule implementing the `Display` trait for the `Isotope`
//! enum.

impl core::fmt::Display for super::Isotope {
    #[allow(clippy::too_many_lines)]
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::H(isotope) => write!(f, "{isotope}"),
            Self::He(isotope) => write!(f, "{isotope}"),
            Self::Li(isotope) => write!(f, "{isotope}"),
            Self::Be(isotope) => write!(f, "{isotope}"),
            Self::B(isotope) => write!(f, "{isotope}"),
            Self::C(isotope) => write!(f, "{isotope}"),
            Self::N(isotope) => write!(f, "{isotope}"),
            Self::O(isotope) => write!(f, "{isotope}"),
            Self::F(isotope) => write!(f, "{isotope}"),
            Self::Ne(isotope) => write!(f, "{isotope}"),
            Self::Na(isotope) => write!(f, "{isotope}"),
            Self::Mg(isotope) => write!(f, "{isotope}"),
            Self::Al(isotope) => write!(f, "{isotope}"),
            Self::Si(isotope) => write!(f, "{isotope}"),
            Self::P(isotope) => write!(f, "{isotope}"),
            Self::S(isotope) => write!(f, "{isotope}"),
            Self::Cl(isotope) => write!(f, "{isotope}"),
            Self::Ar(isotope) => write!(f, "{isotope}"),
            Self::K(isotope) => write!(f, "{isotope}"),
            Self::Ca(isotope) => write!(f, "{isotope}"),
            Self::Sc(isotope) => write!(f, "{isotope}"),
            Self::Ti(isotope) => write!(f, "{isotope}"),
            Self::V(isotope) => write!(f, "{isotope}"),
            Self::Cr(isotope) => write!(f, "{isotope}"),
            Self::Mn(isotope) => write!(f, "{isotope}"),
            Self::Fe(isotope) => write!(f, "{isotope}"),
            Self::Co(isotope) => write!(f, "{isotope}"),
            Self::Ni(isotope) => write!(f, "{isotope}"),
            Self::Cu(isotope) => write!(f, "{isotope}"),
            Self::Zn(isotope) => write!(f, "{isotope}"),
            Self::Ga(isotope) => write!(f, "{isotope}"),
            Self::Ge(isotope) => write!(f, "{isotope}"),
            Self::As(isotope) => write!(f, "{isotope}"),
            Self::Se(isotope) => write!(f, "{isotope}"),
            Self::Br(isotope) => write!(f, "{isotope}"),
            Self::Kr(isotope) => write!(f, "{isotope}"),
            Self::Rb(isotope) => write!(f, "{isotope}"),
            Self::Sr(isotope) => write!(f, "{isotope}"),
            Self::Y(isotope) => write!(f, "{isotope}"),
            Self::Zr(isotope) => write!(f, "{isotope}"),
            Self::Nb(isotope) => write!(f, "{isotope}"),
            Self::Mo(isotope) => write!(f, "{isotope}"),
            Self::Tc(isotope) => write!(f, "{isotope}"),
            Self::Ru(isotope) => write!(f, "{isotope}"),
            Self::Rh(isotope) => write!(f, "{isotope}"),
            Self::Pd(isotope) => write!(f, "{isotope}"),
            Self::Ag(isotope) => write!(f, "{isotope}"),
            Self::Cd(isotope) => write!(f, "{isotope}"),
            Self::In(isotope) => write!(f, "{isotope}"),
            Self::Sn(isotope) => write!(f, "{isotope}"),
            Self::Sb(isotope) => write!(f, "{isotope}"),
            Self::Te(isotope) => write!(f, "{isotope}"),
            Self::I(isotope) => write!(f, "{isotope}"),
            Self::Xe(isotope) => write!(f, "{isotope}"),
            Self::Cs(isotope) => write!(f, "{isotope}"),
            Self::Ba(isotope) => write!(f, "{isotope}"),
            Self::La(isotope) => write!(f, "{isotope}"),
            Self::Ce(isotope) => write!(f, "{isotope}"),
            Self::Pr(isotope) => write!(f, "{isotope}"),
            Self::Nd(isotope) => write!(f, "{isotope}"),
            Self::Pm(isotope) => write!(f, "{isotope}"),
            Self::Sm(isotope) => write!(f, "{isotope}"),
            Self::Eu(isotope) => write!(f, "{isotope}"),
            Self::Gd(isotope) => write!(f, "{isotope}"),
            Self::Tb(isotope) => write!(f, "{isotope}"),
            Self::Dy(isotope) => write!(f, "{isotope}"),
            Self::Ho(isotope) => write!(f, "{isotope}"),
            Self::Er(isotope) => write!(f, "{isotope}"),
            Self::Tm(isotope) => write!(f, "{isotope}"),
            Self::Yb(isotope) => write!(f, "{isotope}"),
            Self::Lu(isotope) => write!(f, "{isotope}"),
            Self::Hf(isotope) => write!(f, "{isotope}"),
            Self::Ta(isotope) => write!(f, "{isotope}"),
            Self::W(isotope) => write!(f, "{isotope}"),
            Self::Re(isotope) => write!(f, "{isotope}"),
            Self::Os(isotope) => write!(f, "{isotope}"),
            Self::Ir(isotope) => write!(f, "{isotope}"),
            Self::Pt(isotope) => write!(f, "{isotope}"),
            Self::Au(isotope) => write!(f, "{isotope}"),
            Self::Hg(isotope) => write!(f, "{isotope}"),
            Self::Tl(isotope) => write!(f, "{isotope}"),
            Self::Pb(isotope) => write!(f, "{isotope}"),
            Self::Bi(isotope) => write!(f, "{isotope}"),
            Self::Po(isotope) => write!(f, "{isotope}"),
            Self::At(isotope) => write!(f, "{isotope}"),
            Self::Rn(isotope) => write!(f, "{isotope}"),
            Self::Fr(isotope) => write!(f, "{isotope}"),
            Self::Ra(isotope) => write!(f, "{isotope}"),
            Self::Ac(isotope) => write!(f, "{isotope}"),
            Self::Th(isotope) => write!(f, "{isotope}"),
            Self::Pa(isotope) => write!(f, "{isotope}"),
            Self::U(isotope) => write!(f, "{isotope}"),
            Self::Np(isotope) => write!(f, "{isotope}"),
            Self::Pu(isotope) => write!(f, "{isotope}"),
            Self::Am(isotope) => write!(f, "{isotope}"),
            Self::Cm(isotope) => write!(f, "{isotope}"),
            Self::Bk(isotope) => write!(f, "{isotope}"),
            Self::Cf(isotope) => write!(f, "{isotope}"),
            Self::Es(isotope) => write!(f, "{isotope}"),
            Self::Fm(isotope) => write!(f, "{isotope}"),
            Self::Md(isotope) => write!(f, "{isotope}"),
            Self::No(isotope) => write!(f, "{isotope}"),
            Self::Lr(isotope) => write!(f, "{isotope}"),
            Self::Rf(isotope) => write!(f, "{isotope}"),
            Self::Db(isotope) => write!(f, "{isotope}"),
            Self::Sg(isotope) => write!(f, "{isotope}"),
            Self::Bh(isotope) => write!(f, "{isotope}"),
            Self::Hs(isotope) => write!(f, "{isotope}"),
            Self::Mt(isotope) => write!(f, "{isotope}"),
            Self::Ds(isotope) => write!(f, "{isotope}"),
            Self::Rg(isotope) => write!(f, "{isotope}"),
            Self::Cn(isotope) => write!(f, "{isotope}"),
            Self::Nh(isotope) => write!(f, "{isotope}"),
            Self::Fl(isotope) => write!(f, "{isotope}"),
            Self::Mc(isotope) => write!(f, "{isotope}"),
            Self::Lv(isotope) => write!(f, "{isotope}"),
            Self::Ts(isotope) => write!(f, "{isotope}"),
            Self::Og(isotope) => write!(f, "{isotope}"),
        }
    }
}

#[cfg(test)]
mod tests {
    use strum::IntoEnumIterator;

    use crate::isotopes::HydrogenIsotope;

    #[test]
    fn test_display() {
        for element in crate::Element::iter() {
            let isotopes = element.isotopes();
            for isotope in isotopes {
                if matches!(isotope, crate::Isotope::H(HydrogenIsotope::D | HydrogenIsotope::T)) {
                    // Skip Hydrogen-1 as its display is just "H"
                    continue;
                }

                let display = alloc::format!("{isotope}");
                assert!(!display.is_empty(), "Display should not be empty for {isotope:?}");
                // Verify that the display string contains the element symbol
                let element_symbol = alloc::format!("{element}");
                assert!(
                    display.contains(&element_symbol),
                    "Display '{display}' for isotope {isotope:?} should contain element symbol '{element_symbol}'",
                );
            }
        }
    }
}