summaryrefslogtreecommitdiff
path: root/src/error.rs
blob: 943c3eca62b00d743683910f6464a978e8665d82 (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
use bincode::Error as bincode_e;
use sled::Error as sled_e;
use std::fmt;

#[derive(Debug)]
pub struct TwinHError(pub String);

impl std::error::Error for TwinHError {}

impl std::fmt::Display for TwinHError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
        write!(f, "Twin H-Power: {}", self.0)
    }
}

impl From<sled_e> for TwinHError {
    fn from(e: sled_e) -> Self {
        Self(format!("database error: {}", e))
    }
}

impl From<bincode_e> for TwinHError {
    fn from(e: bincode_e) -> Self {
        Self(format!("(de)serialization error: {}", e))
    }
}