fits_io/header/
extension_type.rs1use std::error::Error;
2
3#[derive(Debug, Clone, Copy, PartialEq)]
5pub enum ExtensionType {
6 Image,
8 BinTable,
10 AsciiTable,
12}
13
14impl From<ExtensionType> for String {
15 fn from(value: ExtensionType) -> Self {
16 match value {
17 ExtensionType::Image => "IMAGE".to_string(),
18 ExtensionType::BinTable => "BINTABLE".to_string(),
19 ExtensionType::AsciiTable => "TABLE".to_string(),
20 }
21 }
22}
23
24impl TryFrom<String> for ExtensionType {
25 type Error = Box<dyn Error + Send + Sync>;
26
27 fn try_from(value: String) -> Result<Self, Self::Error> {
28 match value.to_uppercase().as_str() {
29 "IMAGE" => Ok(ExtensionType::Image),
30 "TABLE" => Ok(ExtensionType::AsciiTable),
31 "BINTABLE" => Ok(ExtensionType::BinTable),
32 _ => Err(format!("Unknown extension type: {}", value).into()),
33 }
34 }
35}