1use bytes::Bytes;
2
3pub type Result<T> = std::io::Result<T>;
5
6#[derive(Debug, Clone, Copy, Eq, PartialEq)]
8pub enum ErrorKind {
9 Client,
10 Server,
11 UnknownCommand,
12 Auth,
13}
14
15#[derive(Debug, Clone)]
17pub struct Error {
18 pub kind: ErrorKind,
19 pub message: Bytes,
20 pub close: bool,
21}
22
23impl Error {
24 pub fn client<T: Into<Bytes>>(msg: T) -> Self {
25 Self {
26 kind: ErrorKind::Client,
27 message: msg.into(),
28 close: false,
29 }
30 }
31
32 pub fn server<T: Into<Bytes>>(msg: T) -> Self {
33 Self {
34 kind: ErrorKind::Server,
35 message: msg.into(),
36 close: true,
37 }
38 }
39
40 pub fn unknown<T: Into<Bytes>>(msg: T) -> Self {
41 Self {
42 kind: ErrorKind::UnknownCommand,
43 message: msg.into(),
44 close: false,
45 }
46 }
47
48 pub fn auth<T: Into<Bytes>>(msg: T) -> Self {
49 Self {
50 kind: ErrorKind::Auth,
51 message: msg.into(),
52 close: false,
53 }
54 }
55
56 pub fn with_close<T: Into<Bytes>>(kind: ErrorKind, msg: T, close: bool) -> Self {
57 Self {
58 kind,
59 message: msg.into(),
60 close,
61 }
62 }
63}