#[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))]
pub enum SilverIsotope {
Ag92,
Ag93,
Ag94,
Ag95,
Ag96,
Ag97,
Ag98,
Ag99,
Ag100,
Ag101,
Ag102,
Ag103,
Ag104,
Ag105,
Ag106,
Ag107,
Ag108,
Ag109,
Ag110,
Ag111,
Ag112,
Ag113,
Ag114,
Ag115,
Ag116,
Ag117,
Ag118,
Ag119,
Ag120,
Ag121,
Ag122,
Ag123,
Ag124,
Ag125,
Ag126,
Ag127,
Ag128,
Ag129,
Ag130,
Ag131,
Ag132,
}
impl super::RelativeAtomicMass for SilverIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Ag92 => 91.95971f64,
Self::Ag93 => 92.95033f64,
Self::Ag94 => 93.94373f64,
Self::Ag95 => 94.93602f64,
Self::Ag96 => 95.930744f64,
Self::Ag97 => 96.92397f64,
Self::Ag98 => 97.92156f64,
Self::Ag99 => 98.9176458f64,
Self::Ag100 => 99.9161154f64,
Self::Ag101 => 100.912684f64,
Self::Ag102 => 101.9117047f64,
Self::Ag103 => 102.9089631f64,
Self::Ag104 => 103.9086239f64,
Self::Ag105 => 104.9065256f64,
Self::Ag106 => 105.9066636f64,
Self::Ag107 => 106.9050916f64,
Self::Ag108 => 107.9059503f64,
Self::Ag109 => 108.9047553f64,
Self::Ag110 => 109.9061102f64,
Self::Ag111 => 110.9052959f64,
Self::Ag112 => 111.9070486f64,
Self::Ag113 => 112.906573f64,
Self::Ag114 => 113.908823f64,
Self::Ag115 => 114.908767f64,
Self::Ag116 => 115.9113868f64,
Self::Ag117 => 116.911774f64,
Self::Ag118 => 117.9145955f64,
Self::Ag119 => 118.91557f64,
Self::Ag120 => 119.9187848f64,
Self::Ag121 => 120.920125f64,
Self::Ag122 => 121.923664f64,
Self::Ag123 => 122.925337f64,
Self::Ag124 => 123.92893f64,
Self::Ag125 => 124.93105f64,
Self::Ag126 => 125.93475f64,
Self::Ag127 => 126.93711f64,
Self::Ag128 => 127.94106f64,
Self::Ag129 => 128.94395f64,
Self::Ag130 => 129.9507f64,
Self::Ag131 => 130.956253f64,
Self::Ag132 => 131.96307f64,
}
}
}
impl super::ElementVariant for SilverIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Ag
}
}
impl super::MassNumber for SilverIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Ag92 => 92u16,
Self::Ag93 => 93u16,
Self::Ag94 => 94u16,
Self::Ag95 => 95u16,
Self::Ag96 => 96u16,
Self::Ag97 => 97u16,
Self::Ag98 => 98u16,
Self::Ag99 => 99u16,
Self::Ag100 => 100u16,
Self::Ag101 => 101u16,
Self::Ag102 => 102u16,
Self::Ag103 => 103u16,
Self::Ag104 => 104u16,
Self::Ag105 => 105u16,
Self::Ag106 => 106u16,
Self::Ag107 => 107u16,
Self::Ag108 => 108u16,
Self::Ag109 => 109u16,
Self::Ag110 => 110u16,
Self::Ag111 => 111u16,
Self::Ag112 => 112u16,
Self::Ag113 => 113u16,
Self::Ag114 => 114u16,
Self::Ag115 => 115u16,
Self::Ag116 => 116u16,
Self::Ag117 => 117u16,
Self::Ag118 => 118u16,
Self::Ag119 => 119u16,
Self::Ag120 => 120u16,
Self::Ag121 => 121u16,
Self::Ag122 => 122u16,
Self::Ag123 => 123u16,
Self::Ag124 => 124u16,
Self::Ag125 => 125u16,
Self::Ag126 => 126u16,
Self::Ag127 => 127u16,
Self::Ag128 => 128u16,
Self::Ag129 => 129u16,
Self::Ag130 => 130u16,
Self::Ag131 => 131u16,
Self::Ag132 => 132u16,
}
}
}
impl super::IsotopicComposition for SilverIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Ag107 => Some(0.51839f64),
Self::Ag109 => Some(0.48161f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for SilverIsotope {
fn most_abundant_isotope() -> Self {
Self::Ag107
}
}
impl From<SilverIsotope> for crate::Isotope {
fn from(isotope: SilverIsotope) -> Self {
crate::Isotope::Ag(isotope)
}
}
impl From<SilverIsotope> for crate::Element {
fn from(_isotope: SilverIsotope) -> Self {
crate::Element::Ag
}
}
impl TryFrom<u64> for SilverIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
92u64 => Ok(Self::Ag92),
93u64 => Ok(Self::Ag93),
94u64 => Ok(Self::Ag94),
95u64 => Ok(Self::Ag95),
96u64 => Ok(Self::Ag96),
97u64 => Ok(Self::Ag97),
98u64 => Ok(Self::Ag98),
99u64 => Ok(Self::Ag99),
100u64 => Ok(Self::Ag100),
101u64 => Ok(Self::Ag101),
102u64 => Ok(Self::Ag102),
103u64 => Ok(Self::Ag103),
104u64 => Ok(Self::Ag104),
105u64 => Ok(Self::Ag105),
106u64 => Ok(Self::Ag106),
107u64 => Ok(Self::Ag107),
108u64 => Ok(Self::Ag108),
109u64 => Ok(Self::Ag109),
110u64 => Ok(Self::Ag110),
111u64 => Ok(Self::Ag111),
112u64 => Ok(Self::Ag112),
113u64 => Ok(Self::Ag113),
114u64 => Ok(Self::Ag114),
115u64 => Ok(Self::Ag115),
116u64 => Ok(Self::Ag116),
117u64 => Ok(Self::Ag117),
118u64 => Ok(Self::Ag118),
119u64 => Ok(Self::Ag119),
120u64 => Ok(Self::Ag120),
121u64 => Ok(Self::Ag121),
122u64 => Ok(Self::Ag122),
123u64 => Ok(Self::Ag123),
124u64 => Ok(Self::Ag124),
125u64 => Ok(Self::Ag125),
126u64 => Ok(Self::Ag126),
127u64 => Ok(Self::Ag127),
128u64 => Ok(Self::Ag128),
129u64 => Ok(Self::Ag129),
130u64 => Ok(Self::Ag130),
131u64 => Ok(Self::Ag131),
132u64 => Ok(Self::Ag132),
_ => Err(crate::errors::Error::Isotope(crate::Element::Ag, value)),
}
}
}
impl TryFrom<u8> for SilverIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for SilverIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for SilverIsotope {
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 SilverIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Ag92 => write!(f, "Ag92"),
Self::Ag93 => write!(f, "Ag93"),
Self::Ag94 => write!(f, "Ag94"),
Self::Ag95 => write!(f, "Ag95"),
Self::Ag96 => write!(f, "Ag96"),
Self::Ag97 => write!(f, "Ag97"),
Self::Ag98 => write!(f, "Ag98"),
Self::Ag99 => write!(f, "Ag99"),
Self::Ag100 => write!(f, "Ag100"),
Self::Ag101 => write!(f, "Ag101"),
Self::Ag102 => write!(f, "Ag102"),
Self::Ag103 => write!(f, "Ag103"),
Self::Ag104 => write!(f, "Ag104"),
Self::Ag105 => write!(f, "Ag105"),
Self::Ag106 => write!(f, "Ag106"),
Self::Ag107 => write!(f, "Ag107"),
Self::Ag108 => write!(f, "Ag108"),
Self::Ag109 => write!(f, "Ag109"),
Self::Ag110 => write!(f, "Ag110"),
Self::Ag111 => write!(f, "Ag111"),
Self::Ag112 => write!(f, "Ag112"),
Self::Ag113 => write!(f, "Ag113"),
Self::Ag114 => write!(f, "Ag114"),
Self::Ag115 => write!(f, "Ag115"),
Self::Ag116 => write!(f, "Ag116"),
Self::Ag117 => write!(f, "Ag117"),
Self::Ag118 => write!(f, "Ag118"),
Self::Ag119 => write!(f, "Ag119"),
Self::Ag120 => write!(f, "Ag120"),
Self::Ag121 => write!(f, "Ag121"),
Self::Ag122 => write!(f, "Ag122"),
Self::Ag123 => write!(f, "Ag123"),
Self::Ag124 => write!(f, "Ag124"),
Self::Ag125 => write!(f, "Ag125"),
Self::Ag126 => write!(f, "Ag126"),
Self::Ag127 => write!(f, "Ag127"),
Self::Ag128 => write!(f, "Ag128"),
Self::Ag129 => write!(f, "Ag129"),
Self::Ag130 => write!(f, "Ag130"),
Self::Ag131 => write!(f, "Ag131"),
Self::Ag132 => write!(f, "Ag132"),
}
}
}
#[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 SilverIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in SilverIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Ag, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in SilverIsotope::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 SilverIsotope::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 = SilverIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in SilverIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Ag(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in SilverIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Ag);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in SilverIsotope::iter() {
let mass = isotope.mass_number();
let iso = SilverIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = SilverIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = SilverIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(SilverIsotope::try_from(0_u16).is_err());
assert!(SilverIsotope::try_from(1000_u16).is_err());
assert!(SilverIsotope::try_from(0_u32).is_err());
assert!(SilverIsotope::try_from(1000_u32).is_err());
assert!(SilverIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in SilverIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}