summary refs log tree commit diff
path: root/msg_socket2/src/error.rs
blob: 3aa0dd566e0f9ce2454034c93d3c79ebd1563301 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// SPDX-License-Identifier: MIT OR Apache-2.0
// Copyright 2020, Alyssa Ross

use std::fmt::{self, Display, Formatter};

#[derive(Debug)]
pub enum Error {
    DataError(bincode::Error),
    IoError(sys_util::Error),
}

impl Display for Error {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        use Error::*;
        match self {
            DataError(error) => write!(f, "{}", error),
            IoError(error) => write!(f, "{}", error),
        }
    }
}

impl From<bincode::Error> for Error {
    fn from(error: bincode::Error) -> Self {
        Self::DataError(error)
    }
}

impl From<sys_util::Error> for Error {
    fn from(error: sys_util::Error) -> Self {
        Self::IoError(error)
    }
}

impl From<std::io::Error> for Error {
    fn from(error: std::io::Error) -> Self {
        Self::IoError(error.into())
    }
}