rustronomy_fits/err/
img_err.rs

1/*
2    Copyright (C) 2022 Raúl Wolters
3
4    This file is part of rustronomy-fits.
5
6    rustronomy is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation, either version 3 of the License, or
9    (at your option) any later version.
10
11    rustronomy is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with rustronomy.  If not, see <http://www.gnu.org/licenses/>.
18*/
19
20use std::{
21  error::Error,
22  fmt::{self, Display, Formatter},
23};
24
25use crate::{bitpix::Bitpix, extensions::image::TypedImage};
26
27#[derive(Debug)]
28pub struct WrongImgTypeErr {
29  /*
30      This error may be thrown when opening a FITS file. If the FITS
31      file has invalid encoding (for whatever reason), this error will be
32      thrown.
33  */
34  img_type: Bitpix,
35  wrong_type: Bitpix,
36}
37
38impl Error for WrongImgTypeErr {}
39impl Display for WrongImgTypeErr {
40  fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
41    write!(f,
42            "Tried to access {:?} type array as an {} type array. Implicit array type conversions are disallowed",
43            self.img_type, self.wrong_type
44        )
45  }
46}
47
48impl WrongImgTypeErr {
49  pub(crate) fn new(img: &TypedImage, wrong_type: Bitpix) -> Self {
50    WrongImgTypeErr { img_type: img.bpx(), wrong_type: wrong_type }
51  }
52}
53
54#[derive(Debug)]
55pub struct InvalidMemLayout {}
56
57impl Error for InvalidMemLayout {}
58impl Display for InvalidMemLayout {
59  fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
60    write!(f, "Error while encoding image: underlying ndarray uses unsupported memory layout. Only continuous layouts are supported")
61  }
62}
63
64impl InvalidMemLayout {
65  pub(crate) fn new() -> Self {
66    InvalidMemLayout {}
67  }
68}