#[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 NobeliumIsotope {
No248,
No249,
No250,
No251,
No252,
No253,
No254,
No255,
No256,
No257,
No258,
No259,
No260,
No262,
}
impl super::RelativeAtomicMass for NobeliumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::No248 => 248.08655f64,
Self::No249 => 249.0878f64,
Self::No250 => 250.08756f64,
Self::No251 => 251.08894f64,
Self::No252 => 252.088967f64,
Self::No253 => 253.0905641f64,
Self::No254 => 254.090956f64,
Self::No255 => 255.093191f64,
Self::No256 => 256.0942829f64,
Self::No257 => 257.0968878f64,
Self::No258 => 258.09821f64,
Self::No259 => 259.10103f64,
Self::No260 => 260.10264f64,
Self::No262 => 262.10746f64,
}
}
}
impl super::ElementVariant for NobeliumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::No
}
}
impl super::MassNumber for NobeliumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::No248 => 248u16,
Self::No249 => 249u16,
Self::No250 => 250u16,
Self::No251 => 251u16,
Self::No252 => 252u16,
Self::No253 => 253u16,
Self::No254 => 254u16,
Self::No255 => 255u16,
Self::No256 => 256u16,
Self::No257 => 257u16,
Self::No258 => 258u16,
Self::No259 => 259u16,
Self::No260 => 260u16,
Self::No262 => 262u16,
}
}
}
impl super::IsotopicComposition for NobeliumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
None
}
}
impl super::MostAbundantIsotope for NobeliumIsotope {
fn most_abundant_isotope() -> Self {
Self::No262
}
}
impl From<NobeliumIsotope> for crate::Isotope {
fn from(isotope: NobeliumIsotope) -> Self {
crate::Isotope::No(isotope)
}
}
impl From<NobeliumIsotope> for crate::Element {
fn from(_isotope: NobeliumIsotope) -> Self {
crate::Element::No
}
}
impl TryFrom<u64> for NobeliumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
248u64 => Ok(Self::No248),
249u64 => Ok(Self::No249),
250u64 => Ok(Self::No250),
251u64 => Ok(Self::No251),
252u64 => Ok(Self::No252),
253u64 => Ok(Self::No253),
254u64 => Ok(Self::No254),
255u64 => Ok(Self::No255),
256u64 => Ok(Self::No256),
257u64 => Ok(Self::No257),
258u64 => Ok(Self::No258),
259u64 => Ok(Self::No259),
260u64 => Ok(Self::No260),
262u64 => Ok(Self::No262),
_ => Err(crate::errors::Error::Isotope(crate::Element::No, value)),
}
}
}
impl TryFrom<u8> for NobeliumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for NobeliumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for NobeliumIsotope {
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 NobeliumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::No248 => write!(f, "No248"),
Self::No249 => write!(f, "No249"),
Self::No250 => write!(f, "No250"),
Self::No251 => write!(f, "No251"),
Self::No252 => write!(f, "No252"),
Self::No253 => write!(f, "No253"),
Self::No254 => write!(f, "No254"),
Self::No255 => write!(f, "No255"),
Self::No256 => write!(f, "No256"),
Self::No257 => write!(f, "No257"),
Self::No258 => write!(f, "No258"),
Self::No259 => write!(f, "No259"),
Self::No260 => write!(f, "No260"),
Self::No262 => write!(f, "No262"),
}
}
}
#[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 NobeliumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in NobeliumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::No, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in NobeliumIsotope::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 NobeliumIsotope::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 = NobeliumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in NobeliumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::No(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in NobeliumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::No);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in NobeliumIsotope::iter() {
let mass = isotope.mass_number();
let iso = NobeliumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = NobeliumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = NobeliumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(NobeliumIsotope::try_from(0_u16).is_err());
assert!(NobeliumIsotope::try_from(1000_u16).is_err());
assert!(NobeliumIsotope::try_from(0_u32).is_err());
assert!(NobeliumIsotope::try_from(1000_u32).is_err());
assert!(NobeliumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in NobeliumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}