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
58
59
60
61
62
63
64
65
66
use kwap_msg::to_bytes::MessageToBytesError;
use kwap_msg::MessageParseError;
use no_std_net::SocketAddr;
use crate::net::Socket;
use crate::platform::Platform;
#[derive(Debug, Clone, Copy)]
pub enum When {
Polling,
SendingMessage(Option<SocketAddr>, kwap_msg::Id, kwap_msg::Token),
None,
}
impl When {
pub fn what<P: Platform>(self, what: What<P>) -> Error<P> {
Error { when: self, what }
}
}
#[derive(Debug)]
pub struct Error<P: Platform> {
pub what: What<P>,
pub when: When,
}
impl<P: Platform> Error<P> {
pub fn message_parse_error(&self) -> Option<&MessageParseError> {
match self.what {
| What::FromBytes(ref e) => Some(e),
| _ => None,
}
}
}
#[derive(Debug)]
pub enum What<P: Platform> {
SockError(<<P as Platform>::Socket as Socket>::Error),
FromBytes(MessageParseError),
ToBytes(MessageToBytesError),
HostInvalidUtf8(core::str::Utf8Error),
HostInvalidIpAddress,
MessageNeverAcked,
ClockError,
Timeout,
}