periodic_elements/parts/
subshell_labels.rs1use core::str::FromStr;
2
3use alloc::fmt::{Display, Error, Formatter};
4
5use crate::Orbital;
6
7#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
8pub struct SubshellLabels {
9 pub shell: u8,
10 pub orbital: Orbital,
11 pub electron_count: u8,
12}
13
14impl Display for SubshellLabels {
15 fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
16 write!(f, "{}{}{}", self.shell, self.orbital, self.electron_count)
17 }
18}
19
20impl FromStr for SubshellLabels {
21 type Err = ();
22
23 fn from_str(s: &str) -> Result<Self, Self::Err> {
24 Ok(Self {
25 shell: s.get(0..1).ok_or(())?.parse().map_err(|_| ())?,
26 orbital: s.get(1..2).ok_or(())?.parse().map_err(|_| ())?,
27 electron_count: s.get(2..).ok_or(())?.parse().map_err(|_| ())?,
28 })
29 }
30}