@@ -27,10 +27,12 @@ use no_std_net::SocketAddr;
27
27
/// `bind()` call in the creation of such sockets, these are implicitly bound to a suitable local
28
28
/// address at connect time.
29
29
pub trait ConnectedUdp {
30
+ /// Error type returned by send and receive operations.
30
31
type Error : embedded_io:: Error ;
31
32
32
33
/// Send the provided data to the connected peer
33
34
fn send ( & mut self , data : & [ u8 ] ) -> Self :: SendFuture < ' _ > ;
35
+ /// Return type of the [`.send()`] method
34
36
type SendFuture < ' a > : Future < Output = Result < ( ) , Self :: Error > > where Self : ' a ;
35
37
36
38
/// Receive a datagram into the provided buffer.
@@ -45,6 +47,7 @@ pub trait ConnectedUdp {
45
47
/// (a possibility not considered there). The name deviates from the original `receive()` to
46
48
/// make room for a version that is more zero-copy friendly.
47
49
fn receive_into ( & mut self , buffer : & mut [ u8 ] ) -> Self :: ReceiveIntoFuture < ' _ > ;
50
+ /// Return type of the [`.receive_into()`] method
48
51
type ReceiveIntoFuture < ' a > : Future < Output = Result < usize , Self :: Error > > where Self : ' a ;
49
52
50
53
// WIP to allow zero-copy operation
@@ -67,6 +70,7 @@ pub trait ConnectedUdp {
67
70
/// caller MUST pass in the same (or compatible) values, MAY and pass in unspecified values where
68
71
/// applicable. The implementer MAY check them for compatibility, and SHOULD do that in debug mode.
69
72
pub trait UnconnectedUdp {
73
+ /// Error type returned by send and receive operations.
70
74
type Error : embedded_io:: Error ;
71
75
72
76
/// Send the provided data to a peer
@@ -86,13 +90,14 @@ pub trait UnconnectedUdp {
86
90
/// address. Both are valid choices in some situations, and the right choice depends on the
87
91
/// protocol used.
88
92
///
89
- /// Note that users of sockets created through [`UdpSocket ::bind_single()`] should always pass
93
+ /// Note that users of sockets created through [`UdpStack ::bind_single()`] should always pass
90
94
/// in that single address -- even though they've made their intention clear at construction.
91
95
/// They can pass either the one obtained at socket creation time, or the one obtained at
92
96
/// receive time; these should be equal. This allows implementations of the trait to use a
93
97
/// single kind of socket for both sockets bound to a single and sockets bound to multiple
94
98
/// addresses.
95
99
fn send ( & mut self , local : SocketAddr , remote : SocketAddr , data : & [ u8 ] ) -> Self :: SendFuture < ' _ > ;
100
+ /// Return type of the [`.send()`] method
96
101
type SendFuture < ' a > : Future < Output = Result < ( ) , Self :: Error > > where Self : ' a ;
97
102
98
103
/// Receive a datagram into the provided buffer.
@@ -103,8 +108,9 @@ pub trait UnconnectedUdp {
103
108
///
104
109
/// The local and remote address are given, in that order, in the result along with the number
105
110
/// of bytes.
106
- fn receive ( & mut self , buffer : & mut [ u8 ] ) -> Self :: ReceiveFuture < ' _ > ;
107
- type ReceiveFuture < ' a > : Future < Output = Result < ( usize , SocketAddr , SocketAddr ) , Self :: Error > > where Self : ' a ;
111
+ fn receive_into ( & mut self , buffer : & mut [ u8 ] ) -> Self :: ReceiveIntoFuture < ' _ > ;
112
+ /// Return type of the [`.receive_into()`] method
113
+ type ReceiveIntoFuture < ' a > : Future < Output = Result < ( usize , SocketAddr , SocketAddr ) , Self :: Error > > where Self : ' a ;
108
114
}
109
115
110
116
/// This trait is implemented by UDP/IP stacks. The trait allows the underlying driver to
@@ -116,8 +122,11 @@ pub trait UdpStack {
116
122
/// Error type returned on socket creation failure.
117
123
type Error : embedded_io:: Error ;
118
124
125
+ /// Eventual socket return type of the [`.connect()`] method
119
126
type Connected < ' m > : ConnectedUdp where Self : ' m ;
127
+ /// Eventual socket return type of the [`.bind_single()`] method
120
128
type Bound < ' m > : UnconnectedUdp where Self : ' m ;
129
+ /// Eventual return type of the [`.bind_multiple()`] method
121
130
type Unbound < ' m > : UnconnectedUdp where Self : ' m ;
122
131
123
132
/// Create a socket that has a fixed remote address.
@@ -126,8 +135,9 @@ pub trait UdpStack {
126
135
///
127
136
/// While asynchronous traits implemented through GAT can not have provided default methods,
128
137
/// implementers are encouraged to use the hidden `.connect_default()` method if all they would
129
- /// do is delegating to [`connect_from`] with a suitable unspecified local address.
138
+ /// do is delegating to [`. connect_from`] with a suitable unspecified local address.
130
139
fn connect ( & self , remote : SocketAddr ) -> Self :: ConnectFuture < ' _ > ;
140
+ /// Future return type of the [`.connect()`] method
131
141
type ConnectFuture < ' a > : Future < Output = Result < ( SocketAddr , Self :: Connected < ' a > ) , Self :: Error > > where Self : ' a ;
132
142
133
143
/// Create a socket that has a fixed remote address.
@@ -136,6 +146,7 @@ pub trait UdpStack {
136
146
/// network stack at connection time. The full local address is returned along with the
137
147
/// connected socket, primarily for debugging purposes.
138
148
fn connect_from ( & self , local : SocketAddr , remote : SocketAddr ) -> Self :: ConnectFromFuture < ' _ > ;
149
+ /// Future return type of the [`.connect_from()`] method
139
150
type ConnectFromFuture < ' a > : Future < Output = Result < ( SocketAddr , Self :: Connected < ' a > ) , Self :: Error > > where Self : ' a ;
140
151
141
152
/// Helper that implements [`connect()`] using [`connect_from()`].
@@ -159,6 +170,7 @@ pub trait UdpStack {
159
170
/// The full local address is returned along with the bound socket; it may then be passed on to
160
171
/// other protocols for advertising purposes.
161
172
fn bind_single ( & self , local : SocketAddr ) -> Self :: BindSingleFuture < ' _ > ;
173
+ /// Future return type of the [`.bind_single()`] method
162
174
type BindSingleFuture < ' a > : Future < Output = Result < ( SocketAddr , Self :: Bound < ' a > ) , Self :: Error > > where Self : ' a ;
163
175
164
176
/// Create a socket that has no single fixed local address.
@@ -184,5 +196,6 @@ pub trait UdpStack {
184
196
/// binding to `[::]:0`, that is, picking some available port but then still leaving the
185
197
/// interface and IP address unspecified.
186
198
fn bind_multiple ( & self , local : SocketAddr ) -> Self :: BindMultipleFuture < ' _ > ;
199
+ /// Future return type of the [`.bind_multiple()`] method
187
200
type BindMultipleFuture < ' a > : Future < Output = Result < Self :: Unbound < ' a > , Self :: Error > > where Self : ' a ;
188
201
}
0 commit comments