stak_profiler/
error.rs

1use core::{
2    fmt::{self, Display, Formatter},
3    num::ParseIntError,
4};
5use std::{error, io};
6
7/// An error.
8#[derive(Debug, Clone, Eq, PartialEq)]
9pub enum Error {
10    /// I/O failure.
11    Io(String),
12    /// A missing call record.
13    MissingCallRecord,
14    /// A missing record type.
15    MissingProcedureOperation,
16    /// A missing stack.
17    MissingStack,
18    /// A missing time.
19    MissingTime,
20    /// Integer parse failure.
21    ParseInt(ParseIntError),
22    /// An unknown record type.
23    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}