rustronomy_fits/err/
hdu_err.rs1use std::{
21 error::Error,
22 fmt::{self, Display, Formatter},
23 ops::Not,
24};
25
26#[derive(Debug)]
27pub struct MissingRecordError {
28 missing_keyword: String,
35}
36
37impl Error for MissingRecordError {}
38impl Display for MissingRecordError {
39 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
40 write!(
41 f,
42 "Keyword {} required for decoding/encoding this HDU is missing!",
43 self.missing_keyword
44 )?;
45 Ok(())
46 }
47}
48impl MissingRecordError {
49 pub fn new(missing_keyword: &str) -> Self {
50 MissingRecordError { missing_keyword: String::from(missing_keyword) }
51 }
52}
53
54#[derive(Debug)]
55pub struct InvalidRecordValueError {
56 keyword: String,
63 invalid_value: String,
64 allowed_values: &'static [&'static str],
65}
66
67impl Error for InvalidRecordValueError {}
68impl Display for InvalidRecordValueError {
69 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
70 write!(
71 f,
72 "The value '{}' is not allowed for the keyword ({}). Allowed values are: {:?}",
73 self.invalid_value, self.keyword, self.allowed_values
74 )?;
75 Ok(())
76 }
77}
78impl InvalidRecordValueError {
79 pub fn new(keyword: &str, invalid_value: &str, allowed_values: &'static [&str]) -> Self {
80 InvalidRecordValueError {
81 keyword: String::from(keyword),
82 invalid_value: String::from(invalid_value),
83 allowed_values: allowed_values,
84 }
85 }
86}
87
88#[derive(Debug)]
89pub struct NotImplementedErr {
90 xtnsion: String,
92}
93
94impl Error for NotImplementedErr {}
95impl Display for NotImplementedErr {
96 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
97 write!(f, "Error while constructing HDU: extension {} not yet implemented", self.xtnsion)
98 }
99}
100
101impl NotImplementedErr {
102 pub fn new(xtnsion: String) -> Self {
103 NotImplementedErr { xtnsion: xtnsion }
104 }
105}