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
use embedded_time::TimeError;
use crate::network::Error as NetworkError;
use crate::services::data::Error as DataServiceError;
#[derive(Debug, PartialEq)]
pub enum GenericError {
Timeout,
Time(TimeError),
Unsupported,
}
impl From<TimeError> for GenericError {
fn from(e: TimeError) -> Self {
GenericError::Time(e)
}
}
#[derive(Debug, PartialEq)]
#[non_exhaustive]
pub enum Error {
BaudDetection,
Busy,
Uninitialized,
StateTimeout,
Network(NetworkError),
DataService(DataServiceError),
Generic(GenericError),
_Unknown,
}
impl From<DataServiceError> for Error {
fn from(e: DataServiceError) -> Self {
match e {
DataServiceError::Generic(g) => Error::Generic(g),
DataServiceError::Network(g) => Error::Network(g),
_ => Error::DataService(e),
}
}
}
impl From<NetworkError> for Error {
fn from(e: NetworkError) -> Self {
match e {
NetworkError::Generic(g) => Error::Generic(g),
_ => Error::Network(e),
}
}
}
impl From<TimeError> for Error {
fn from(e: TimeError) -> Self {
Error::Generic(e.into())
}
}