1
- use edge_nal:: io:: Error ;
2
1
/// Re-export the `edge-nal` crate
3
2
pub use edge_nal:: * ;
4
3
@@ -8,8 +7,6 @@ pub mod std {
8
7
pub use edge_nal_std:: * ;
9
8
10
9
impl super :: NetStack for Stack {
11
- type Error = std:: io:: Error ;
12
-
13
10
type UdpBind < ' a >
14
11
= & ' a Stack
15
12
where
@@ -55,28 +52,216 @@ pub mod std {
55
52
}
56
53
}
57
54
55
+ /// Noop implementations for the `edge-nal` traits.
56
+ /// All of these panic when called
57
+ // TODO: Move to `edge-nal`
58
+ pub mod noop {
59
+ use core:: {
60
+ convert:: Infallible ,
61
+ net:: { Ipv4Addr , SocketAddr } ,
62
+ } ;
63
+
64
+ use edge_nal:: io:: { ErrorType , Read , Write } ;
65
+ use edge_nal:: {
66
+ Close , MulticastV4 , MulticastV6 , Readable , TcpAccept , TcpBind , TcpConnect , TcpShutdown ,
67
+ TcpSplit , UdpBind , UdpConnect , UdpReceive , UdpSend , UdpSplit ,
68
+ } ;
69
+
70
+ /// A type that implements all `edge-nal` traits but does not support any operation
71
+ /// and panics when any method is called.
72
+ pub struct NoopNet ;
73
+
74
+ impl UdpBind for NoopNet {
75
+ type Error = Infallible ;
76
+
77
+ type Socket < ' a >
78
+ = NoopNet
79
+ where
80
+ Self : ' a ;
81
+
82
+ async fn bind ( & self , _local : SocketAddr ) -> Result < Self :: Socket < ' _ > , Self :: Error > {
83
+ panic ! ( "UDP bind not supported" )
84
+ }
85
+ }
86
+
87
+ impl UdpConnect for NoopNet {
88
+ type Error = Infallible ;
89
+
90
+ type Socket < ' a >
91
+ = NoopNet
92
+ where
93
+ Self : ' a ;
94
+
95
+ async fn connect (
96
+ & self ,
97
+ _local : SocketAddr ,
98
+ _remote : SocketAddr ,
99
+ ) -> Result < Self :: Socket < ' _ > , Self :: Error > {
100
+ panic ! ( "UDP connect not supported" )
101
+ }
102
+ }
103
+
104
+ impl TcpBind for NoopNet {
105
+ type Error = Infallible ;
106
+
107
+ type Accept < ' a >
108
+ = NoopNet
109
+ where
110
+ Self : ' a ;
111
+
112
+ async fn bind ( & self , _local : SocketAddr ) -> Result < Self :: Accept < ' _ > , Self :: Error > {
113
+ panic ! ( "TCP bind not supported" )
114
+ }
115
+ }
116
+
117
+ impl TcpAccept for NoopNet {
118
+ type Error = Infallible ;
119
+
120
+ type Socket < ' a >
121
+ = NoopNet
122
+ where
123
+ Self : ' a ;
124
+
125
+ async fn accept ( & self ) -> Result < ( SocketAddr , Self :: Socket < ' _ > ) , Self :: Error > {
126
+ panic ! ( "TCP accept not supported" )
127
+ }
128
+ }
129
+
130
+ impl TcpConnect for NoopNet {
131
+ type Error = Infallible ;
132
+
133
+ type Socket < ' a >
134
+ = NoopNet
135
+ where
136
+ Self : ' a ;
137
+
138
+ async fn connect ( & self , _remote : SocketAddr ) -> Result < Self :: Socket < ' _ > , Self :: Error > {
139
+ panic ! ( "TCP connect not supported" )
140
+ }
141
+ }
142
+
143
+ impl ErrorType for NoopNet {
144
+ type Error = Infallible ;
145
+ }
146
+
147
+ impl Readable for NoopNet {
148
+ async fn readable ( & mut self ) -> Result < ( ) , Self :: Error > {
149
+ panic ! ( "Readable not supported" )
150
+ }
151
+ }
152
+
153
+ impl UdpSend for NoopNet {
154
+ async fn send ( & mut self , _remote : SocketAddr , _data : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
155
+ panic ! ( "UDP send not supported" )
156
+ }
157
+ }
158
+
159
+ impl UdpReceive for NoopNet {
160
+ async fn receive (
161
+ & mut self ,
162
+ _buffer : & mut [ u8 ] ,
163
+ ) -> Result < ( usize , SocketAddr ) , Self :: Error > {
164
+ panic ! ( "UDP receive not supported" )
165
+ }
166
+ }
167
+
168
+ impl UdpSplit for NoopNet {
169
+ type Receive < ' a > = Self ;
170
+ type Send < ' a > = Self ;
171
+
172
+ fn split ( & mut self ) -> ( Self :: Send < ' _ > , Self :: Receive < ' _ > ) {
173
+ panic ! ( "UDP split not supported" )
174
+ }
175
+ }
176
+
177
+ impl MulticastV4 for NoopNet {
178
+ async fn join_v4 (
179
+ & mut self ,
180
+ _multicast_addr : Ipv4Addr ,
181
+ _interface : Ipv4Addr ,
182
+ ) -> Result < ( ) , Self :: Error > {
183
+ panic ! ( "Multicast join not supported" )
184
+ }
185
+
186
+ async fn leave_v4 (
187
+ & mut self ,
188
+ _multicast_addr : Ipv4Addr ,
189
+ _interface : Ipv4Addr ,
190
+ ) -> Result < ( ) , Self :: Error > {
191
+ panic ! ( "Multicast leave not supported" )
192
+ }
193
+ }
194
+
195
+ impl MulticastV6 for NoopNet {
196
+ async fn join_v6 (
197
+ & mut self ,
198
+ _multicast_addr : core:: net:: Ipv6Addr ,
199
+ _interface : u32 ,
200
+ ) -> Result < ( ) , Self :: Error > {
201
+ panic ! ( "Multicast join not supported" )
202
+ }
203
+
204
+ async fn leave_v6 (
205
+ & mut self ,
206
+ _multicast_addr : core:: net:: Ipv6Addr ,
207
+ _interface : u32 ,
208
+ ) -> Result < ( ) , Self :: Error > {
209
+ panic ! ( "Multicast leave not supported" )
210
+ }
211
+ }
212
+
213
+ impl Read for NoopNet {
214
+ async fn read ( & mut self , _buf : & mut [ u8 ] ) -> Result < usize , Self :: Error > {
215
+ panic ! ( "Read not supported" )
216
+ }
217
+ }
218
+
219
+ impl Write for NoopNet {
220
+ async fn write ( & mut self , _buf : & [ u8 ] ) -> Result < usize , Self :: Error > {
221
+ panic ! ( "Write not supported" )
222
+ }
223
+ }
224
+
225
+ impl TcpSplit for NoopNet {
226
+ type Read < ' a > = Self ;
227
+ type Write < ' a > = Self ;
228
+
229
+ fn split ( & mut self ) -> ( Self :: Write < ' _ > , Self :: Read < ' _ > ) {
230
+ panic ! ( "TCP split not supported" )
231
+ }
232
+ }
233
+
234
+ impl TcpShutdown for NoopNet {
235
+ async fn close ( & mut self , _what : Close ) -> Result < ( ) , Self :: Error > {
236
+ panic ! ( "TCP shutdown not supported" )
237
+ }
238
+
239
+ async fn abort ( & mut self ) -> Result < ( ) , Self :: Error > {
240
+ panic ! ( "TCP abort not supported" )
241
+ }
242
+ }
243
+ }
244
+
58
245
/// The network stack used by `rs-matter-stack`
59
246
///
60
247
/// Depending on the platform and features enabled, the stack
61
248
/// might or might not support certain protocols.
62
249
pub trait NetStack {
63
- type Error : Error ;
64
-
65
- type UdpBind < ' a > : UdpBind < Error = Self :: Error >
250
+ type UdpBind < ' a > : UdpBind
66
251
where
67
252
Self : ' a ;
68
- type UdpConnect < ' a > : UdpConnect < Error = Self :: Error >
253
+ type UdpConnect < ' a > : UdpConnect
69
254
where
70
255
Self : ' a ;
71
256
72
- type TcpBind < ' a > : TcpBind < Error = Self :: Error >
257
+ type TcpBind < ' a > : TcpBind
73
258
where
74
259
Self : ' a ;
75
- type TcpConnect < ' a > : TcpConnect < Error = Self :: Error >
260
+ type TcpConnect < ' a > : TcpConnect
76
261
where
77
262
Self : ' a ;
78
263
79
- type Dns < ' a > : Dns < Error = Self :: Error >
264
+ type Dns < ' a > : Dns
80
265
where
81
266
Self : ' a ;
82
267
@@ -100,8 +285,6 @@ impl<T> NetStack for &T
100
285
where
101
286
T : NetStack ,
102
287
{
103
- type Error = T :: Error ;
104
-
105
288
type UdpBind < ' a >
106
289
= T :: UdpBind < ' a >
107
290
where
0 commit comments