mqtt3/
error.rs

1use std::result;
2use std::io;
3use std::string::FromUtf8Error;
4use byteorder;
5
6pub type Result<T> = result::Result<T, Error>;
7
8#[derive(Debug)]
9pub enum Error {
10    IncorrectPacketFormat,
11    InvalidTopicPath,
12    UnsupportedProtocolName,
13    UnsupportedProtocolVersion,
14    UnsupportedQualityOfService,
15    UnsupportedPacketType,
16    UnsupportedConnectReturnCode,
17    PayloadSizeIncorrect,
18    PayloadTooLong,
19    PayloadRequired,
20    TopicNameMustNotContainNonUtf8,
21    TopicNameMustNotContainWildcard,
22    MalformedRemainingLength,
23    UnexpectedEof,
24    Io(io::Error)
25}
26
27impl From<io::Error> for Error {
28    fn from(err: io::Error) -> Error {
29        Error::Io(err)
30    }
31}
32
33impl From<FromUtf8Error> for Error {
34    fn from(_: FromUtf8Error) -> Error {
35        Error::TopicNameMustNotContainNonUtf8
36    }
37}
38
39impl From<byteorder::Error> for Error {
40    fn from(err: byteorder::Error) -> Error {
41        match err {
42            byteorder::Error::UnexpectedEOF => Error::UnexpectedEof,
43            byteorder::Error::Io(err) => Error::Io(err)
44        }
45    }
46}