1use std::{io, str};
2
3#[derive(Debug)]
4pub enum ParseError {
5 InvalidProtocol,
6 InvalidLength,
7 UnsupportedProtocolLevel,
8 ConnectReservedFlagSet,
9 ConnAckReservedFlagSet,
10 InvalidClientId,
11 UnsupportedPacketType,
12 PacketIdRequired,
13 MaxSizeExceeded,
14 IoError(io::Error),
15 Utf8Error(str::Utf8Error),
16}
17
18impl PartialEq for ParseError {
19 fn eq(&self, other: &Self) -> bool {
20 match self {
21 ParseError::InvalidProtocol => match other {
22 ParseError::InvalidProtocol => true,
23 _ => false,
24 },
25 ParseError::InvalidLength => match other {
26 ParseError::InvalidLength => true,
27 _ => false,
28 },
29 ParseError::UnsupportedProtocolLevel => match other {
30 ParseError::UnsupportedProtocolLevel => true,
31 _ => false,
32 },
33 ParseError::ConnectReservedFlagSet => match other {
34 ParseError::ConnectReservedFlagSet => true,
35 _ => false,
36 },
37 ParseError::ConnAckReservedFlagSet => match other {
38 ParseError::ConnAckReservedFlagSet => true,
39 _ => false,
40 },
41 ParseError::InvalidClientId => match other {
42 ParseError::InvalidClientId => true,
43 _ => false,
44 },
45 ParseError::UnsupportedPacketType => match other {
46 ParseError::UnsupportedPacketType => true,
47 _ => false,
48 },
49 ParseError::PacketIdRequired => match other {
50 ParseError::PacketIdRequired => true,
51 _ => false,
52 },
53 ParseError::MaxSizeExceeded => match other {
54 ParseError::MaxSizeExceeded => true,
55 _ => false,
56 },
57 ParseError::IoError(_) => false,
58 ParseError::Utf8Error(_) => false,
59 }
60 }
61}
62
63impl From<io::Error> for ParseError {
64 fn from(err: io::Error) -> Self {
65 ParseError::IoError(err)
66 }
67}
68
69impl From<str::Utf8Error> for ParseError {
70 fn from(err: str::Utf8Error) -> Self {
71 ParseError::Utf8Error(err)
72 }
73}
74
75#[derive(Copy, Clone, Debug, PartialEq)]
76pub enum TopicError {
77 InvalidTopic,
78 InvalidLevel,
79}