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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
use std::{io, str}; #[derive(Debug)] pub enum ParseError { InvalidProtocol, InvalidLength, MalformedPacket, UnsupportedProtocolLevel, ConnectReservedFlagSet, ConnAckReservedFlagSet, InvalidClientId, UnsupportedPacketType, PacketIdRequired, MaxSizeExceeded, IoError(io::Error), Utf8Error(str::Utf8Error), } impl PartialEq for ParseError { fn eq(&self, other: &Self) -> bool { match (self, other) { (ParseError::InvalidProtocol, ParseError::InvalidProtocol) => true, (ParseError::InvalidLength, ParseError::InvalidLength) => true, (ParseError::UnsupportedProtocolLevel, ParseError::UnsupportedProtocolLevel) => { true } (ParseError::ConnectReservedFlagSet, ParseError::ConnectReservedFlagSet) => true, (ParseError::ConnAckReservedFlagSet, ParseError::ConnAckReservedFlagSet) => true, (ParseError::InvalidClientId, ParseError::InvalidClientId) => true, (ParseError::UnsupportedPacketType, ParseError::UnsupportedPacketType) => true, (ParseError::PacketIdRequired, ParseError::PacketIdRequired) => true, (ParseError::MaxSizeExceeded, ParseError::MaxSizeExceeded) => true, (ParseError::MalformedPacket, ParseError::MalformedPacket) => true, (ParseError::IoError(_), _) => false, (ParseError::Utf8Error(_), _) => false, _ => false, } } } impl From<io::Error> for ParseError { fn from(err: io::Error) -> Self { ParseError::IoError(err) } } impl From<str::Utf8Error> for ParseError { fn from(err: str::Utf8Error) -> Self { ParseError::Utf8Error(err) } } #[derive(Copy, Clone, Debug, PartialEq)] pub enum TopicError { InvalidTopic, InvalidLevel, }