1use std::fmt;
2
3#[derive(Debug)]
5pub enum Error {
6 OutOfMemory,
8 HandlerAlreadyInstalled,
11 Io(std::io::Error),
13}
14
15impl std::error::Error for Error {
16 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
17 match self {
18 Self::Io(inner) => Some(inner),
19 _ => None,
20 }
21 }
22}
23
24impl fmt::Display for Error {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 match self {
27 Self::OutOfMemory => f.write_str("unable to allocate memory"),
28 Self::HandlerAlreadyInstalled => {
29 f.write_str("an exception handler is already installed")
30 }
31 Self::Io(e) => write!(f, "{}", e),
32 }
33 }
34}
35
36impl From<std::io::Error> for Error {
37 fn from(e: std::io::Error) -> Self {
38 Self::Io(e)
39 }
40}