djin_protocol/
errors.rs

1use std::{self, fmt, error};
2
3
4#[derive(Debug, Copy, Clone, PartialEq, Eq)]
5/// Copy of [TryFromIntError](https://doc.rust-lang.org/std/num/struct.TryFromIntError.html)
6/// that works in stable rust
7pub struct TryFromIntError { }
8
9impl TryFromIntError {
10    fn description(&self) -> &str {
11        "out of range integral type conversion attempted"
12    }
13}
14
15impl fmt::Display for TryFromIntError {
16    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
17        self.description().fmt(fmt)
18    }
19}
20
21impl error::Error for TryFromIntError {
22    fn description(&self) -> &str {
23        self.description()
24    }
25}
26
27#[derive(Debug, Copy, Clone, PartialEq, Eq)]
28/// Copy of [CharTryFromError](https://doc.rust-lang.org/std/char/struct.CharTryFromError.html)
29/// that works in stable rust
30pub struct CharTryFromError { }
31
32impl CharTryFromError {
33    fn description(&self) -> &str {
34         "converted integer out of range for `char`"
35    }
36}
37
38impl fmt::Display for CharTryFromError {
39    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
40       self.description().fmt(f)
41    }
42}
43
44impl error::Error for CharTryFromError {
45    fn description(&self) -> &str {
46        self.description()
47    }
48}
49
50error_chain! {
51    types {
52        Error, ErrorKind, ResultExt;
53    }
54
55    foreign_links {
56        Io(std::io::Error);
57        FromUtf8(std::string::FromUtf8Error);
58        FromNulError(std::ffi::NulError);
59        TryFromIntError(TryFromIntError);
60        CharTryFromError(CharTryFromError);
61
62        UuidParseError(::uuid::Error) #[cfg(feature = "uuid")];
63    }
64
65    errors {
66        UnknownPacketId {
67            description("unknown packet identifier")
68            display("unknown packet identifier")
69        }
70
71        /// A parcel type was read that has not been implemented yet.
72        UnimplementedParcel(type_name: &'static str) {
73            description("unimplemented parcel")
74            display("unimplemented parcel type '{}", type_name)
75        }
76    }
77}
78