periodic_elements/parts/
block.rs

1use core::str::FromStr;
2use alloc::fmt::{Display, Error, Formatter};
3#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
4pub enum Block {
5	Nonmetal,
6	NobleGas,
7	AlkaliMetal,
8	AlkalineEarthMetal,
9	Metalloid,
10	Halogen,
11	Metal,
12	Lanthanoid,
13	Actinoid,
14	TransitionMetal,
15	PostTransitionMetal,
16}
17
18impl FromStr for Block {
19	type Err = ();
20
21	fn from_str(s: &str) -> Result<Self, Self::Err> {
22		match s {
23			"nonmetal" => Ok(Block::Nonmetal),
24			"noble gas" => Ok(Block::NobleGas),
25			"alkali metal" => Ok(Block::AlkaliMetal),
26			"alkaline earth metal" => Ok(Block::AlkalineEarthMetal),
27			"metalloid" => Ok(Block::Metalloid),
28			"halogen" => Ok(Block::Halogen),
29			"metal" => Ok(Block::Metal),
30			"lanthanoid" => Ok(Block::Lanthanoid),
31			"actinoid" => Ok(Block::Actinoid),
32			"transition metal" => Ok(Block::TransitionMetal),
33			"post-transition metal" => Ok(Block::PostTransitionMetal),
34			_ => Err(()),
35		}
36	}
37}
38
39impl Display for Block {
40	fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
41		write!(f, "{}", match self {
42			Block::Nonmetal => "Nonmetal",
43			Block::NobleGas => "Noble gas",
44			Block::AlkaliMetal => "Alkali metal",
45			Block::AlkalineEarthMetal => "Alkaline earth metal",
46			Block::Metalloid => "Metalloid",
47			Block::Halogen => "Halogen",
48			Block::Metal => "Metal",
49			Block::Lanthanoid => "Lanthanoid",
50			Block::Actinoid => "Actinoid",
51			Block::TransitionMetal => "Transition metal",
52			Block::PostTransitionMetal => "Post-transition metal",
53		})
54	}
55}