1use alloc::string::String;
4use core::fmt;
5
6#[derive(Clone, Debug, PartialEq, Eq)]
9pub enum HDF5Error {
10 InvalidSignature,
12 UnsupportedVersion(u8),
14 ChunkedNotSupported,
17 FilteredNotSupported,
20 UnsupportedDtype,
22 NotFound(String),
24 ShapeMismatch,
26 Truncated,
28 InvalidHeader,
30 RankNotSupported,
32 TypeMismatch,
34 DenseGroupsNotSupported,
36 NameTooLong,
38 #[cfg(feature = "std")]
40 Io(String),
41}
42
43impl fmt::Display for HDF5Error {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 match self {
46 Self::InvalidSignature => f.write_str("invalid HDF5 signature"),
47 Self::UnsupportedVersion(v) => write!(f, "unsupported HDF5 version {v}"),
48 Self::ChunkedNotSupported => f.write_str("chunked dataset not supported"),
49 Self::FilteredNotSupported => f.write_str("filtered HDF5 dataset not supported"),
50 Self::UnsupportedDtype => f.write_str("HDF5 datatype not supported"),
51 Self::NotFound(p) => write!(f, "HDF5 path not found: {p}"),
52 Self::ShapeMismatch => f.write_str("HDF5 dataspace shape mismatch"),
53 Self::Truncated => f.write_str("truncated HDF5 file"),
54 Self::InvalidHeader => f.write_str("invalid HDF5 header"),
55 Self::RankNotSupported => f.write_str("HDF5 rank not supported"),
56 Self::TypeMismatch => f.write_str("HDF5 datatype mismatch"),
57 Self::DenseGroupsNotSupported => f.write_str("dense HDF5 groups not supported"),
58 Self::NameTooLong => f.write_str("HDF5 name too long"),
59 #[cfg(feature = "std")]
60 Self::Io(s) => write!(f, "HDF5 I/O error: {s}"),
61 }
62 }
63}
64
65#[cfg(feature = "std")]
66impl std::error::Error for HDF5Error {}
67
68#[cfg(feature = "std")]
69impl From<std::io::Error> for HDF5Error {
70 fn from(e: std::io::Error) -> Self {
71 Self::Io(alloc::string::ToString::to_string(&e))
72 }
73}
74
75pub type Result<T> = core::result::Result<T, HDF5Error>;