1use core::{
2 fmt::{self, Display, Formatter},
3 num::ParseIntError,
4};
5use std::{error, io};
6
7#[derive(Debug, Clone, Eq, PartialEq)]
9pub enum Error {
10 Io(String),
12 MissingCallRecord,
14 MissingProcedureOperation,
16 MissingStack,
18 MissingTime,
20 ParseInt(ParseIntError),
22 UnknownRecordType,
24}
25
26impl Display for Error {
27 fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
28 match self {
29 Self::Io(error) => write!(formatter, "{error}"),
30 Self::MissingCallRecord => write!(formatter, "missing call record"),
31 Self::MissingProcedureOperation => write!(formatter, "missing record type"),
32 Self::MissingStack => write!(formatter, "missing stack"),
33 Self::MissingTime => write!(formatter, "missing time"),
34 Self::ParseInt(error) => write!(formatter, "{error}"),
35 Self::UnknownRecordType => write!(formatter, "unknown record type"),
36 }
37 }
38}
39
40impl error::Error for Error {}
41
42impl From<io::Error> for Error {
43 fn from(error: io::Error) -> Self {
44 Self::Io(error.to_string())
45 }
46}
47
48impl From<ParseIntError> for Error {
49 fn from(error: ParseIntError) -> Self {
50 Self::ParseInt(error)
51 }
52}