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}
13
14#[derive(Debug, Clone)]
16pub struct Error {
17 pub kind: ErrorKind,
18 pub message: Bytes,
19 pub close: bool,
20}
21
22impl Error {
23 pub fn client<T: Into<Bytes>>(msg: T) -> Self {
24 Self {
25 kind: ErrorKind::Client,
26 message: msg.into(),
27 close: false,
28 }
29 }
30
31 pub fn server<T: Into<Bytes>>(msg: T) -> Self {
32 Self {
33 kind: ErrorKind::Server,
34 message: msg.into(),
35 close: true,
36 }
37 }
38
39 pub fn unknown<T: Into<Bytes>>(msg: T) -> Self {
40 Self {
41 kind: ErrorKind::UnknownCommand,
42 message: msg.into(),
43 close: false,
44 }
45 }
46
47 pub fn with_close<T: Into<Bytes>>(kind: ErrorKind, msg: T, close: bool) -> Self {
48 Self {
49 kind,
50 message: msg.into(),
51 close,
52 }
53 }
54}