tinkerforge_async/
converting_receiver.rs1#[derive(Debug, Copy, Clone)]
4pub enum BrickletError {
5 InvalidParameter,
7 FunctionNotSupported,
9 UnknownError,
11 NotConnected,
13 SuccessButResponseExpectedIsDisabled,
15}
16
17impl From<u8> for BrickletError {
18 fn from(byte: u8) -> BrickletError {
19 match byte {
20 1 => BrickletError::InvalidParameter,
21 2 => BrickletError::FunctionNotSupported,
22 _ => BrickletError::UnknownError,
23 }
24 }
25}
26
27impl std::fmt::Display for BrickletError {
28 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
29 write!(
30 f,
31 "{}",
32 match &self {
33 BrickletError::InvalidParameter => "A parameter was invalid or had an unexpected length.",
34 BrickletError::FunctionNotSupported => "The brick or bricklet does not support the requested function.",
35 BrickletError::UnknownError => "UnknownError, Currently unused",
36 BrickletError::NotConnected => "The request can not be fulfulled, as there is currently no connection to a brick daemon.",
37 BrickletError::SuccessButResponseExpectedIsDisabled =>
38 "The request was sent, but response expected is disabled, so no response can be received. This is not an error.",
39 }
40 )
41 }
42}
43
44impl std::error::Error for BrickletError {}
45
46#[derive(Copy, Clone, Debug, PartialEq)]
48pub enum BrickletRecvTimeoutError {
49 QueueDisconnected,
51 QueueTimeout,
53 InvalidParameter,
55 FunctionNotSupported,
57 UnknownError,
59 MalformedPacket,
61 NotConnected,
63 SuccessButResponseExpectedIsDisabled,
65}
66
67impl std::fmt::Display for BrickletRecvTimeoutError {
68 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
69 write!(
70 f,
71 "{}",
72 match &self {
73 BrickletRecvTimeoutError::QueueDisconnected =>
74 "The queue was disconnected. This usually happens if the ip connection is destroyed.",
75 BrickletRecvTimeoutError::QueueTimeout => "The request could not be responded to before the timeout was reached.",
76 BrickletRecvTimeoutError::InvalidParameter => "A parameter was invalid or had an unexpected length.",
77 BrickletRecvTimeoutError::FunctionNotSupported => "The brick or bricklet does not support the requested function.",
78 BrickletRecvTimeoutError::UnknownError => "UnknownError, Currently unused",
79 BrickletRecvTimeoutError::MalformedPacket =>
80 "The received packet had an unexpected length. Maybe a function was called on a wrong brick or bricklet?",
81 BrickletRecvTimeoutError::NotConnected =>
82 "The request can not be fulfulled, as there is currently no connection to a brick daemon.",
83 BrickletRecvTimeoutError::SuccessButResponseExpectedIsDisabled =>
84 "The request was sent, but response expected is disabled, so no response can be received. This is not an error.",
85 }
86 )
87 }
88}
89
90impl std::error::Error for BrickletRecvTimeoutError {}
91
92#[derive(Copy, Clone, Debug, PartialEq)]
94pub enum BrickletTryRecvError {
95 QueueDisconnected,
97 QueueEmpty,
99 InvalidParameter,
101 FunctionNotSupported,
103 UnknownError,
105 MalformedPacket,
107 NotConnected,
109 SuccessButResponseExpectedIsDisabled,
111}
112
113impl std::fmt::Display for BrickletTryRecvError {
114 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
115 write!(
116 f,
117 "{}",
118 match &self {
119 BrickletTryRecvError::QueueDisconnected =>
120 "The queue was disconnected. This usually happens if the ip connection is destroyed.",
121 BrickletTryRecvError::QueueEmpty => "There are currently no responses available.",
122 BrickletTryRecvError::InvalidParameter => "A parameter was invalid or had an unexpected length.",
123 BrickletTryRecvError::FunctionNotSupported => "The brick or bricklet does not support the requested function.",
124 BrickletTryRecvError::UnknownError => "UnknownError, Currently unused",
125 BrickletTryRecvError::MalformedPacket =>
126 "The received packet had an unexpected length. Maybe a function was called on a wrong brick or bricklet?",
127 BrickletTryRecvError::NotConnected =>
128 "The request can not be fulfulled, as there is currently no connection to a brick daemon.",
129 BrickletTryRecvError::SuccessButResponseExpectedIsDisabled =>
130 "The request was sent, but response expected is disabled, so no response can be received. This is not an error.",
131 }
132 )
133 }
134}
135
136impl std::error::Error for BrickletTryRecvError {}