1use std::fmt::Display;
3use std::fmt::Formatter;
4use serde_derive::{Deserialize, Serialize};
5
6
7#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
8pub enum ErrorKind {
9 Key,
10 Wallet,
11 Network,
12 Input,
13 NoResource,
14 Internal,
15}
16
17impl Display for ErrorKind {
18 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
19 match self {
20 ErrorKind::Input => write!(f, "Input"),
21 ErrorKind::Internal => write!(f, "OpError"),
22 ErrorKind::Key => write!(f, "KeyError"),
23 ErrorKind::Wallet => write!(f, "WalletError"),
24 ErrorKind::Network => write!(f, "NetworkError"),
25 ErrorKind::NoResource => write!(f, "NoResourceFound"),
26
27 }
28 }
29}
30
31impl PartialEq for ErrorKind {
32 fn eq(&self,rs: &ErrorKind) -> bool {
33 self.to_string() == rs.to_string()
34 }
35}
36
37
38#[derive(Serialize, Deserialize, Debug, Clone)]
39pub struct S5Error {
40 pub kind: String,
41 pub message: String,
42}
43
44impl S5Error {
45 pub fn new(kind: ErrorKind, message: &str) -> Self {
46 S5Error {
47 kind: kind.to_string(),
48 message: message.to_string(),
49 }
50 }
51 }