#[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))]
pub enum ErbiumIsotope {
Er142,
Er143,
Er144,
Er145,
Er146,
Er147,
Er148,
Er149,
Er150,
Er151,
Er152,
Er153,
Er154,
Er155,
Er156,
Er157,
Er158,
Er159,
Er160,
Er161,
Er162,
Er163,
Er164,
Er165,
Er166,
Er167,
Er168,
Er169,
Er170,
Er171,
Er172,
Er173,
Er174,
Er175,
Er176,
Er177,
Er178,
Er179,
Er180,
}
impl super::RelativeAtomicMass for ErbiumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Er142 => 141.9701f64,
Self::Er143 => 142.96662f64,
Self::Er144 => 143.9607f64,
Self::Er145 => 144.95805f64,
Self::Er146 => 145.9524184f64,
Self::Er147 => 146.949964f64,
Self::Er148 => 147.944735f64,
Self::Er149 => 148.942306f64,
Self::Er150 => 149.937916f64,
Self::Er151 => 150.937449f64,
Self::Er152 => 151.935057f64,
Self::Er153 => 152.93508f64,
Self::Er154 => 153.9327908f64,
Self::Er155 => 154.9332159f64,
Self::Er156 => 155.931067f64,
Self::Er157 => 156.931949f64,
Self::Er158 => 157.929893f64,
Self::Er159 => 158.9306918f64,
Self::Er160 => 159.929077f64,
Self::Er161 => 160.9300046f64,
Self::Er162 => 161.9287884f64,
Self::Er163 => 162.9300408f64,
Self::Er164 => 163.9292088f64,
Self::Er165 => 164.9307345f64,
Self::Er166 => 165.9302995f64,
Self::Er167 => 166.9320546f64,
Self::Er168 => 167.9323767f64,
Self::Er169 => 168.9345968f64,
Self::Er170 => 169.9354702f64,
Self::Er171 => 170.9380357f64,
Self::Er172 => 171.9393619f64,
Self::Er173 => 172.9424f64,
Self::Er174 => 173.94423f64,
Self::Er175 => 174.94777f64,
Self::Er176 => 175.94994f64,
Self::Er177 => 176.95399f64,
Self::Er178 => 177.956779f64,
Self::Er179 => 178.961267f64,
Self::Er180 => 179.96438f64,
}
}
}
impl super::ElementVariant for ErbiumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Er
}
}
impl super::MassNumber for ErbiumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Er142 => 142u16,
Self::Er143 => 143u16,
Self::Er144 => 144u16,
Self::Er145 => 145u16,
Self::Er146 => 146u16,
Self::Er147 => 147u16,
Self::Er148 => 148u16,
Self::Er149 => 149u16,
Self::Er150 => 150u16,
Self::Er151 => 151u16,
Self::Er152 => 152u16,
Self::Er153 => 153u16,
Self::Er154 => 154u16,
Self::Er155 => 155u16,
Self::Er156 => 156u16,
Self::Er157 => 157u16,
Self::Er158 => 158u16,
Self::Er159 => 159u16,
Self::Er160 => 160u16,
Self::Er161 => 161u16,
Self::Er162 => 162u16,
Self::Er163 => 163u16,
Self::Er164 => 164u16,
Self::Er165 => 165u16,
Self::Er166 => 166u16,
Self::Er167 => 167u16,
Self::Er168 => 168u16,
Self::Er169 => 169u16,
Self::Er170 => 170u16,
Self::Er171 => 171u16,
Self::Er172 => 172u16,
Self::Er173 => 173u16,
Self::Er174 => 174u16,
Self::Er175 => 175u16,
Self::Er176 => 176u16,
Self::Er177 => 177u16,
Self::Er178 => 178u16,
Self::Er179 => 179u16,
Self::Er180 => 180u16,
}
}
}
impl super::IsotopicComposition for ErbiumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Er162 => Some(0.00139f64),
Self::Er164 => Some(0.01601f64),
Self::Er166 => Some(0.33503f64),
Self::Er167 => Some(0.22869f64),
Self::Er168 => Some(0.26978f64),
Self::Er170 => Some(0.1491f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for ErbiumIsotope {
fn most_abundant_isotope() -> Self {
Self::Er166
}
}
impl From<ErbiumIsotope> for crate::Isotope {
fn from(isotope: ErbiumIsotope) -> Self {
crate::Isotope::Er(isotope)
}
}
impl From<ErbiumIsotope> for crate::Element {
fn from(_isotope: ErbiumIsotope) -> Self {
crate::Element::Er
}
}
impl TryFrom<u64> for ErbiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
142u64 => Ok(Self::Er142),
143u64 => Ok(Self::Er143),
144u64 => Ok(Self::Er144),
145u64 => Ok(Self::Er145),
146u64 => Ok(Self::Er146),
147u64 => Ok(Self::Er147),
148u64 => Ok(Self::Er148),
149u64 => Ok(Self::Er149),
150u64 => Ok(Self::Er150),
151u64 => Ok(Self::Er151),
152u64 => Ok(Self::Er152),
153u64 => Ok(Self::Er153),
154u64 => Ok(Self::Er154),
155u64 => Ok(Self::Er155),
156u64 => Ok(Self::Er156),
157u64 => Ok(Self::Er157),
158u64 => Ok(Self::Er158),
159u64 => Ok(Self::Er159),
160u64 => Ok(Self::Er160),
161u64 => Ok(Self::Er161),
162u64 => Ok(Self::Er162),
163u64 => Ok(Self::Er163),
164u64 => Ok(Self::Er164),
165u64 => Ok(Self::Er165),
166u64 => Ok(Self::Er166),
167u64 => Ok(Self::Er167),
168u64 => Ok(Self::Er168),
169u64 => Ok(Self::Er169),
170u64 => Ok(Self::Er170),
171u64 => Ok(Self::Er171),
172u64 => Ok(Self::Er172),
173u64 => Ok(Self::Er173),
174u64 => Ok(Self::Er174),
175u64 => Ok(Self::Er175),
176u64 => Ok(Self::Er176),
177u64 => Ok(Self::Er177),
178u64 => Ok(Self::Er178),
179u64 => Ok(Self::Er179),
180u64 => Ok(Self::Er180),
_ => Err(crate::errors::Error::Isotope(crate::Element::Er, value)),
}
}
}
impl TryFrom<u8> for ErbiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for ErbiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for ErbiumIsotope {
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 ErbiumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Er142 => write!(f, "Er142"),
Self::Er143 => write!(f, "Er143"),
Self::Er144 => write!(f, "Er144"),
Self::Er145 => write!(f, "Er145"),
Self::Er146 => write!(f, "Er146"),
Self::Er147 => write!(f, "Er147"),
Self::Er148 => write!(f, "Er148"),
Self::Er149 => write!(f, "Er149"),
Self::Er150 => write!(f, "Er150"),
Self::Er151 => write!(f, "Er151"),
Self::Er152 => write!(f, "Er152"),
Self::Er153 => write!(f, "Er153"),
Self::Er154 => write!(f, "Er154"),
Self::Er155 => write!(f, "Er155"),
Self::Er156 => write!(f, "Er156"),
Self::Er157 => write!(f, "Er157"),
Self::Er158 => write!(f, "Er158"),
Self::Er159 => write!(f, "Er159"),
Self::Er160 => write!(f, "Er160"),
Self::Er161 => write!(f, "Er161"),
Self::Er162 => write!(f, "Er162"),
Self::Er163 => write!(f, "Er163"),
Self::Er164 => write!(f, "Er164"),
Self::Er165 => write!(f, "Er165"),
Self::Er166 => write!(f, "Er166"),
Self::Er167 => write!(f, "Er167"),
Self::Er168 => write!(f, "Er168"),
Self::Er169 => write!(f, "Er169"),
Self::Er170 => write!(f, "Er170"),
Self::Er171 => write!(f, "Er171"),
Self::Er172 => write!(f, "Er172"),
Self::Er173 => write!(f, "Er173"),
Self::Er174 => write!(f, "Er174"),
Self::Er175 => write!(f, "Er175"),
Self::Er176 => write!(f, "Er176"),
Self::Er177 => write!(f, "Er177"),
Self::Er178 => write!(f, "Er178"),
Self::Er179 => write!(f, "Er179"),
Self::Er180 => write!(f, "Er180"),
}
}
}
#[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 ErbiumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in ErbiumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Er, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in ErbiumIsotope::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 ErbiumIsotope::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 = ErbiumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in ErbiumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Er(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in ErbiumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Er);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in ErbiumIsotope::iter() {
let mass = isotope.mass_number();
let iso = ErbiumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = ErbiumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = ErbiumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(ErbiumIsotope::try_from(0_u16).is_err());
assert!(ErbiumIsotope::try_from(1000_u16).is_err());
assert!(ErbiumIsotope::try_from(0_u32).is_err());
assert!(ErbiumIsotope::try_from(1000_u32).is_err());
assert!(ErbiumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in ErbiumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}