1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
pub use ptable::Element; #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct Isotope { ion: Ion, neutrons: Option<u16> } impl Isotope { pub fn new(ion: Ion, neutrons: Option<u16>) -> Isotope { Isotope { ion, neutrons } } pub fn from_element(element: Element, neutrons: Option<u16>) -> Isotope { Self::new(Ion::from(element), neutrons) } #[inline(always)] pub fn get_ion(&self) -> &Ion { &self.ion } #[inline(always)] pub fn get_ion_mut(&mut self) -> &mut Ion { &mut self.ion } #[inline(always)] pub fn get_neutrons_count(&self) -> &Option<u16> { &self.neutrons } #[inline(always)] pub fn get_neutrons_count_mut(&mut self) -> &mut Option<u16> { &mut self.neutrons } #[inline(always)] pub fn get_element(&self) -> &Element { self.ion.get_element() } #[inline(always)] pub fn get_element_mut(&mut self) -> &mut Element { self.ion.get_element_mut() } } impl From<Element> for Isotope { fn from(i: Element) -> Isotope { Isotope::from_element(i, None) } } impl From<Ion> for Isotope { fn from(i: Ion) -> Isotope { Isotope::new(i, None) } } impl AsRef<Ion> for Isotope { fn as_ref(&self) -> &Ion { &self.ion } } impl AsMut<Ion> for Isotope { fn as_mut(&mut self) -> &mut Ion { &mut self.ion } } #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct Ion { element: Element, charge: i8 } impl Ion { pub fn new(element: Element, charge: i8) -> Ion { Ion { element, charge } } #[inline(always)] pub fn get_element(&self) -> &Element { &self.element } #[inline(always)] pub fn get_element_mut(&mut self) -> &mut Element { &mut self.element } #[inline(always)] pub fn set_element(&mut self, element: Element) { self.element = element; } #[inline(always)] pub fn get_charge(&self) -> &i8 { &self.charge } #[inline(always)] pub fn get_charge_mut(&mut self) -> &mut i8 { &mut self.charge } #[inline(always)] pub fn set_charge(&mut self, charge: i8) { self.charge = charge; } } impl From<Element> for Ion { fn from(e: Element) -> Ion { Ion::new(e, 0) } } impl AsRef<Element> for Ion { fn as_ref(&self) -> &Element { &self.element } } impl AsMut<Element> for Ion { fn as_mut(&mut self) -> &mut Element { &mut self.element } } #[cfg(test)] mod tests { #[test] fn it_works() { assert_eq!(2 + 2, 4); } }