#[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 RutherfordiumIsotope {
Rf253,
Rf254,
Rf255,
Rf256,
Rf257,
Rf258,
Rf259,
Rf260,
Rf261,
Rf262,
Rf263,
Rf265,
Rf267,
}
impl super::RelativeAtomicMass for RutherfordiumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Rf253 => 253.10044f64,
Self::Rf254 => 254.10005f64,
Self::Rf255 => 255.10127f64,
Self::Rf256 => 256.101152f64,
Self::Rf257 => 257.102918f64,
Self::Rf258 => 258.103428f64,
Self::Rf259 => 259.105596f64,
Self::Rf260 => 260.10644f64,
Self::Rf261 => 261.108773f64,
Self::Rf262 => 262.10992f64,
Self::Rf263 => 263.11249f64,
Self::Rf265 => 265.11668f64,
Self::Rf267 => 267.12179f64,
}
}
}
impl super::ElementVariant for RutherfordiumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Rf
}
}
impl super::MassNumber for RutherfordiumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Rf253 => 253u16,
Self::Rf254 => 254u16,
Self::Rf255 => 255u16,
Self::Rf256 => 256u16,
Self::Rf257 => 257u16,
Self::Rf258 => 258u16,
Self::Rf259 => 259u16,
Self::Rf260 => 260u16,
Self::Rf261 => 261u16,
Self::Rf262 => 262u16,
Self::Rf263 => 263u16,
Self::Rf265 => 265u16,
Self::Rf267 => 267u16,
}
}
}
impl super::IsotopicComposition for RutherfordiumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
None
}
}
impl super::MostAbundantIsotope for RutherfordiumIsotope {
fn most_abundant_isotope() -> Self {
Self::Rf267
}
}
impl From<RutherfordiumIsotope> for crate::Isotope {
fn from(isotope: RutherfordiumIsotope) -> Self {
crate::Isotope::Rf(isotope)
}
}
impl From<RutherfordiumIsotope> for crate::Element {
fn from(_isotope: RutherfordiumIsotope) -> Self {
crate::Element::Rf
}
}
impl TryFrom<u64> for RutherfordiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
253u64 => Ok(Self::Rf253),
254u64 => Ok(Self::Rf254),
255u64 => Ok(Self::Rf255),
256u64 => Ok(Self::Rf256),
257u64 => Ok(Self::Rf257),
258u64 => Ok(Self::Rf258),
259u64 => Ok(Self::Rf259),
260u64 => Ok(Self::Rf260),
261u64 => Ok(Self::Rf261),
262u64 => Ok(Self::Rf262),
263u64 => Ok(Self::Rf263),
265u64 => Ok(Self::Rf265),
267u64 => Ok(Self::Rf267),
_ => Err(crate::errors::Error::Isotope(crate::Element::Rf, value)),
}
}
}
impl TryFrom<u8> for RutherfordiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for RutherfordiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for RutherfordiumIsotope {
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 RutherfordiumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Rf253 => write!(f, "Rf253"),
Self::Rf254 => write!(f, "Rf254"),
Self::Rf255 => write!(f, "Rf255"),
Self::Rf256 => write!(f, "Rf256"),
Self::Rf257 => write!(f, "Rf257"),
Self::Rf258 => write!(f, "Rf258"),
Self::Rf259 => write!(f, "Rf259"),
Self::Rf260 => write!(f, "Rf260"),
Self::Rf261 => write!(f, "Rf261"),
Self::Rf262 => write!(f, "Rf262"),
Self::Rf263 => write!(f, "Rf263"),
Self::Rf265 => write!(f, "Rf265"),
Self::Rf267 => write!(f, "Rf267"),
}
}
}
#[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 RutherfordiumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in RutherfordiumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Rf, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in RutherfordiumIsotope::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 RutherfordiumIsotope::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 = RutherfordiumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in RutherfordiumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Rf(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in RutherfordiumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Rf);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in RutherfordiumIsotope::iter() {
let mass = isotope.mass_number();
let iso = RutherfordiumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = RutherfordiumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = RutherfordiumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(RutherfordiumIsotope::try_from(0_u16).is_err());
assert!(RutherfordiumIsotope::try_from(1000_u16).is_err());
assert!(RutherfordiumIsotope::try_from(0_u32).is_err());
assert!(RutherfordiumIsotope::try_from(1000_u32).is_err());
assert!(RutherfordiumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in RutherfordiumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}