rustronomy_fits/err/
img_err.rs1use 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 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}