stellar_class/
spectral_types.rs1use crate::error::Error;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
7pub enum SpectralType {
8 O,
9 B,
10 A,
11 F,
12 G,
13 K,
14 M,
15}
16
17impl TryFrom<&str> for SpectralType {
18 type Error = Error;
19
20 fn try_from(value: &str) -> Result<Self, Self::Error> {
21 let spectral_type = match value {
22 "O" => SpectralType::O,
23 "B" => SpectralType::B,
24 "A" => SpectralType::A,
25 "F" => SpectralType::F,
26 "G" => SpectralType::G,
27 "K" => SpectralType::K,
28 "M" => SpectralType::M,
29 _ => return Err(Error::InvalidSpectralType),
30 };
31
32 Ok(spectral_type)
33 }
34}
35
36impl Into<&'static str> for SpectralType {
37 fn into(self) -> &'static str {
38 match self {
39 SpectralType::O => "O",
40 SpectralType::B => "B",
41 SpectralType::A => "A",
42 SpectralType::F => "F",
43 SpectralType::G => "G",
44 SpectralType::K => "K",
45 SpectralType::M => "M",
46 }
47 }
48}