fitsrs/hdu/header/extension/
mod.rs

1pub mod asciitable;
2pub mod bintable;
3pub mod image;
4
5use std::str::FromStr;
6
7use async_trait::async_trait;
8use serde::Serialize;
9
10use super::ValueMap;
11use crate::error::Error;
12
13#[derive(PartialEq, Eq, Clone, Copy, Debug, Serialize)]
14pub enum XtensionType {
15    Image,
16    BinTable,
17    AsciiTable,
18}
19
20impl XtensionType {
21    pub fn as_str(&self) -> &'static str {
22        match self {
23            XtensionType::Image => "IMAGE",
24            XtensionType::BinTable => "BINTABLE",
25            XtensionType::AsciiTable => "TABLE",
26        }
27    }
28}
29
30impl std::fmt::Display for XtensionType {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        f.write_str(self.as_str())
33    }
34}
35
36impl FromStr for XtensionType {
37    type Err = Error;
38
39    fn from_str(value: &str) -> Result<Self, Self::Err> {
40        match value {
41            "IMAGE" | "IUEIMAGE" => Ok(XtensionType::Image),
42            "TABLE" => Ok(XtensionType::AsciiTable),
43            "BINTABLE" => Ok(XtensionType::BinTable),
44            _ => Err(Error::NotSupportedXtensionType(value.to_owned())),
45        }
46    }
47}
48
49#[async_trait(?Send)]
50pub trait Xtension {
51    /// Return the total size in bytes of the data area
52    fn get_num_bytes_data_block(&self) -> u64;
53
54    // Parse the Xtension keywords
55    // During the parsing, some checks will be made
56    fn parse(values: &ValueMap) -> Result<Self, Error>
57    where
58        Self: Sized;
59}