| 1 | use super::Isotope; |
| 2 | |
| 3 | #[cfg(feature = "ranges")] |
| 4 | /// Range from the minimum to the maximum neutron number across all isotopes |
| 5 | /// |
| 6 | /// Convenience constant to avoid writing the code below when this range is needed: |
| 7 | /// |
| 8 | /// ``` |
| 9 | /// use mendeleev::{Isotope, ISOTOPE_NEUTRON_NUMBER_RANGE}; |
| 10 | /// let all_values = Isotope::iter().map(|e| e.neutron_number()); |
| 11 | /// let min = all_values.clone().min().unwrap(); |
| 12 | /// let max = all_values.max().unwrap(); |
| 13 | /// assert_eq!(min..=max, ISOTOPE_NEUTRON_NUMBER_RANGE); |
| 14 | /// ``` |
| 15 | pub const ISOTOPE_NEUTRON_NUMBER_RANGE: core::ops::RangeInclusive<u32> = 0..=177; |
| 16 | |
| 17 | impl Isotope { |
| 18 | /// Returns the neutron number of the isotope, |
| 19 | /// i.e., the number of neutrons in its nucleus |
| 20 | /// |
| 21 | /// ``` |
| 22 | /// use mendeleev::Isotope; |
| 23 | /// assert_eq!(Isotope::H1.neutron_number(), 0); |
| 24 | /// assert_eq!(Isotope::Og295.neutron_number(), 177); |
| 25 | /// ``` |
| 26 | pub const fn neutron_number(&self) -> u32 { |
| 27 | self.mass_number() |
| 28 | .saturating_sub(self.element().atomic_number()) |
| 29 | } |
| 30 | } |