1#[derive(Debug)]
2pub enum RaknetError {
3 SetRaknetRawSocketError,
4 NotListen,
5 BindAddressError,
6 ConnectionClosed,
7 NotSupportVersion,
8 IncorrectReply,
9 PacketParseError,
10 SocketError,
11 IncorrectReliability,
12 IncorrectPacketID,
13 ReadPacketBufferError,
14 PacketSizeExceedMTU,
15 PacketHeaderError,
16 SetMotdError,
17}
18
19pub type Result<T> = std::result::Result<T, RaknetError>;
20
21impl std::fmt::Display for RaknetError {
22 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23 let message = match self {
24 Self::SetRaknetRawSocketError => {
25 "failed to initialize RakNet from the supplied UDP socket"
26 }
27 Self::NotListen => "the RakNet listener is not listening",
28 Self::BindAddressError => "failed to bind the UDP socket",
29 Self::ConnectionClosed => "the RakNet connection is closed",
30 Self::NotSupportVersion => "the RakNet protocol version is not supported",
31 Self::IncorrectReply => "received an incorrect RakNet reply",
32 Self::PacketParseError => "failed to parse a RakNet packet",
33 Self::SocketError => "a UDP socket operation failed",
34 Self::IncorrectReliability => "the packet reliability is invalid",
35 Self::IncorrectPacketID => "the RakNet packet identifier is invalid",
36 Self::ReadPacketBufferError => "the packet buffer ended unexpectedly",
37 Self::PacketSizeExceedMTU => "the packet exceeds the connection MTU",
38 Self::PacketHeaderError => "the packet has an invalid header",
39 Self::SetMotdError => "failed to update the server MOTD",
40 };
41 formatter.write_str(message)
42 }
43}
44
45impl std::error::Error for RaknetError {}