castep_cell_parser/error/
mod.rs1use std::fmt::Display;
2
3#[derive(Debug)]
4pub enum CellParseError {
5 FileReadingFailure,
6 UnexpectedLength,
7 UnexpectedValueType,
8 Invalid,
9 GetBlockDataFailure,
10 GetFieldDataFailure,
11 RequiredSectionMissing,
12 UnexpectedBlockType((String, String)),
14}
15
16impl Display for CellParseError {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18 match self {
19 Self::UnexpectedLength => f.write_str("Unexpected length of data"),
20 Self::UnexpectedValueType => f.write_str("Unexpected value type"),
21 Self::Invalid => f.write_str("Not valid keywords or data in `.cell`"),
22 Self::GetBlockDataFailure => f.write_str("Fail to get block data"),
23 Self::GetFieldDataFailure => f.write_str("Fail to get field data"),
24 Self::RequiredSectionMissing => {
25 f.write_str("Missing lattice parameters and/or ionic positions!")
26 }
27 Self::FileReadingFailure => f.write_str("Failed to read from file"),
28 Self::UnexpectedBlockType((expected, curr)) => {
29 write!(
30 f,
31 "wrong block name: expect {} but curr: {}",
32 expected, curr
33 )
34 }
35 }
36 }
37}
38
39impl std::error::Error for CellParseError {}