#[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 BromineIsotope {
Br67,
Br68,
Br69,
Br70,
Br71,
Br72,
Br73,
Br74,
Br75,
Br76,
Br77,
Br78,
Br79,
Br80,
Br81,
Br82,
Br83,
Br84,
Br85,
Br86,
Br87,
Br88,
Br89,
Br90,
Br91,
Br92,
Br93,
Br94,
Br95,
Br96,
Br97,
Br98,
}
impl super::RelativeAtomicMass for BromineIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Br67 => 66.96465f64,
Self::Br68 => 67.95873f64,
Self::Br69 => 68.950497f64,
Self::Br70 => 69.944792f64,
Self::Br71 => 70.9393422f64,
Self::Br72 => 71.9365886f64,
Self::Br73 => 72.9316715f64,
Self::Br74 => 73.9299102f64,
Self::Br75 => 74.9258105f64,
Self::Br76 => 75.924542f64,
Self::Br77 => 76.9213792f64,
Self::Br78 => 77.9211459f64,
Self::Br79 => 78.9183376f64,
Self::Br80 => 79.9185298f64,
Self::Br81 => 80.9162897f64,
Self::Br82 => 81.9168032f64,
Self::Br83 => 82.9151756f64,
Self::Br84 => 83.916496f64,
Self::Br85 => 84.9156458f64,
Self::Br86 => 85.9188054f64,
Self::Br87 => 86.920674f64,
Self::Br88 => 87.9240833f64,
Self::Br89 => 88.9267046f64,
Self::Br90 => 89.9312928f64,
Self::Br91 => 90.9343986f64,
Self::Br92 => 91.9396316f64,
Self::Br93 => 92.94313f64,
Self::Br94 => 93.9489f64,
Self::Br95 => 94.95301f64,
Self::Br96 => 95.95903f64,
Self::Br97 => 96.96344f64,
Self::Br98 => 97.96946f64,
}
}
}
impl super::ElementVariant for BromineIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Br
}
}
impl super::MassNumber for BromineIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Br67 => 67u16,
Self::Br68 => 68u16,
Self::Br69 => 69u16,
Self::Br70 => 70u16,
Self::Br71 => 71u16,
Self::Br72 => 72u16,
Self::Br73 => 73u16,
Self::Br74 => 74u16,
Self::Br75 => 75u16,
Self::Br76 => 76u16,
Self::Br77 => 77u16,
Self::Br78 => 78u16,
Self::Br79 => 79u16,
Self::Br80 => 80u16,
Self::Br81 => 81u16,
Self::Br82 => 82u16,
Self::Br83 => 83u16,
Self::Br84 => 84u16,
Self::Br85 => 85u16,
Self::Br86 => 86u16,
Self::Br87 => 87u16,
Self::Br88 => 88u16,
Self::Br89 => 89u16,
Self::Br90 => 90u16,
Self::Br91 => 91u16,
Self::Br92 => 92u16,
Self::Br93 => 93u16,
Self::Br94 => 94u16,
Self::Br95 => 95u16,
Self::Br96 => 96u16,
Self::Br97 => 97u16,
Self::Br98 => 98u16,
}
}
}
impl super::IsotopicComposition for BromineIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Br79 => Some(0.5069f64),
Self::Br81 => Some(0.4931f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for BromineIsotope {
fn most_abundant_isotope() -> Self {
Self::Br79
}
}
impl From<BromineIsotope> for crate::Isotope {
fn from(isotope: BromineIsotope) -> Self {
crate::Isotope::Br(isotope)
}
}
impl From<BromineIsotope> for crate::Element {
fn from(_isotope: BromineIsotope) -> Self {
crate::Element::Br
}
}
impl TryFrom<u64> for BromineIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
67u64 => Ok(Self::Br67),
68u64 => Ok(Self::Br68),
69u64 => Ok(Self::Br69),
70u64 => Ok(Self::Br70),
71u64 => Ok(Self::Br71),
72u64 => Ok(Self::Br72),
73u64 => Ok(Self::Br73),
74u64 => Ok(Self::Br74),
75u64 => Ok(Self::Br75),
76u64 => Ok(Self::Br76),
77u64 => Ok(Self::Br77),
78u64 => Ok(Self::Br78),
79u64 => Ok(Self::Br79),
80u64 => Ok(Self::Br80),
81u64 => Ok(Self::Br81),
82u64 => Ok(Self::Br82),
83u64 => Ok(Self::Br83),
84u64 => Ok(Self::Br84),
85u64 => Ok(Self::Br85),
86u64 => Ok(Self::Br86),
87u64 => Ok(Self::Br87),
88u64 => Ok(Self::Br88),
89u64 => Ok(Self::Br89),
90u64 => Ok(Self::Br90),
91u64 => Ok(Self::Br91),
92u64 => Ok(Self::Br92),
93u64 => Ok(Self::Br93),
94u64 => Ok(Self::Br94),
95u64 => Ok(Self::Br95),
96u64 => Ok(Self::Br96),
97u64 => Ok(Self::Br97),
98u64 => Ok(Self::Br98),
_ => Err(crate::errors::Error::Isotope(crate::Element::Br, value)),
}
}
}
impl TryFrom<u8> for BromineIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for BromineIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for BromineIsotope {
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 BromineIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Br67 => write!(f, "Br67"),
Self::Br68 => write!(f, "Br68"),
Self::Br69 => write!(f, "Br69"),
Self::Br70 => write!(f, "Br70"),
Self::Br71 => write!(f, "Br71"),
Self::Br72 => write!(f, "Br72"),
Self::Br73 => write!(f, "Br73"),
Self::Br74 => write!(f, "Br74"),
Self::Br75 => write!(f, "Br75"),
Self::Br76 => write!(f, "Br76"),
Self::Br77 => write!(f, "Br77"),
Self::Br78 => write!(f, "Br78"),
Self::Br79 => write!(f, "Br79"),
Self::Br80 => write!(f, "Br80"),
Self::Br81 => write!(f, "Br81"),
Self::Br82 => write!(f, "Br82"),
Self::Br83 => write!(f, "Br83"),
Self::Br84 => write!(f, "Br84"),
Self::Br85 => write!(f, "Br85"),
Self::Br86 => write!(f, "Br86"),
Self::Br87 => write!(f, "Br87"),
Self::Br88 => write!(f, "Br88"),
Self::Br89 => write!(f, "Br89"),
Self::Br90 => write!(f, "Br90"),
Self::Br91 => write!(f, "Br91"),
Self::Br92 => write!(f, "Br92"),
Self::Br93 => write!(f, "Br93"),
Self::Br94 => write!(f, "Br94"),
Self::Br95 => write!(f, "Br95"),
Self::Br96 => write!(f, "Br96"),
Self::Br97 => write!(f, "Br97"),
Self::Br98 => write!(f, "Br98"),
}
}
}
#[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 BromineIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in BromineIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Br, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in BromineIsotope::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 BromineIsotope::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 = BromineIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in BromineIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Br(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in BromineIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Br);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in BromineIsotope::iter() {
let mass = isotope.mass_number();
let iso = BromineIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = BromineIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = BromineIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(BromineIsotope::try_from(0_u16).is_err());
assert!(BromineIsotope::try_from(1000_u16).is_err());
assert!(BromineIsotope::try_from(0_u32).is_err());
assert!(BromineIsotope::try_from(1000_u32).is_err());
assert!(BromineIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in BromineIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}