periodic_elements/parts/
bonding_type.rs1use core::str::FromStr;
2use alloc::fmt::{Display, Error, Formatter};
3#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
4pub enum BondingType {
5 Diatomic,
6 Atomic,
7 Metallic,
8 CovalentNetwork,
9}
10
11impl FromStr for BondingType {
12 type Err = ();
13
14 fn from_str(s: &str) -> Result<Self, Self::Err> {
15 match s {
16 "diatomic" => Ok(BondingType::Diatomic),
17 "atomic" => Ok(BondingType::Atomic),
18 "metallic" => Ok(BondingType::Metallic),
19 "covalent network" => Ok(BondingType::CovalentNetwork),
20 _ => Err(()),
21 }
22 }
23}
24
25impl Display for BondingType {
26 fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
27 write!(f, "{}", match self {
28 BondingType::Diatomic => "Diatomic",
29 BondingType::Atomic => "Atomic",
30 BondingType::Metallic => "Metallic",
31 BondingType::CovalentNetwork => "Covalent network",
32 })
33 }
34}