Skip to content

Commit 3f716ac

Browse files
committed
async UDP: Documentation fixes; receive_into consistency
One trait's receive_into still used the old receive name.
1 parent e52dd7e commit 3f716ac

File tree

1 file changed

+19
-5
lines changed
  • embedded-nal-async/src/stack

1 file changed

+19
-5
lines changed

embedded-nal-async/src/stack/udp.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ use no_std_net::SocketAddr;
2727
/// `bind()` call in the creation of such sockets, these are implicitly bound to a suitable local
2828
/// address at connect time.
2929
pub trait ConnectedUdp {
30+
/// Error type returned by send and receive operations.
3031
type Error: embedded_io::Error;
3132

3233
/// Send the provided data to the connected peer
3334
fn send(&mut self, data: &[u8]) -> Self::SendFuture<'_>;
35+
/// Return type of the [`.send()`] method
3436
type SendFuture<'a>: Future<Output = Result<(), Self::Error>>
3537
where
3638
Self: 'a;
@@ -47,6 +49,7 @@ pub trait ConnectedUdp {
4749
/// (a possibility not considered there). The name deviates from the original `receive()` to
4850
/// make room for a version that is more zero-copy friendly.
4951
fn receive_into(&mut self, buffer: &mut [u8]) -> Self::ReceiveIntoFuture<'_>;
52+
/// Return type of the [`.receive_into()`] method
5053
type ReceiveIntoFuture<'a>: Future<Output = Result<usize, Self::Error>>
5154
where
5255
Self: 'a;
@@ -71,6 +74,7 @@ pub trait ConnectedUdp {
7174
/// caller MUST pass in the same (or compatible) values, MAY and pass in unspecified values where
7275
/// applicable. The implementer MAY check them for compatibility, and SHOULD do that in debug mode.
7376
pub trait UnconnectedUdp {
77+
/// Error type returned by send and receive operations.
7478
type Error: embedded_io::Error;
7579

7680
/// Send the provided data to a peer
@@ -90,13 +94,14 @@ pub trait UnconnectedUdp {
9094
/// address. Both are valid choices in some situations, and the right choice depends on the
9195
/// protocol used.
9296
///
93-
/// Note that users of sockets created through [`UdpSocket::bind_single()`] should always pass
97+
/// Note that users of sockets created through [`UdpStack::bind_single()`] should always pass
9498
/// in that single address -- even though they've made their intention clear at construction.
9599
/// They can pass either the one obtained at socket creation time, or the one obtained at
96100
/// receive time; these should be equal. This allows implementations of the trait to use a
97101
/// single kind of socket for both sockets bound to a single and sockets bound to multiple
98102
/// addresses.
99103
fn send(&mut self, local: SocketAddr, remote: SocketAddr, data: &[u8]) -> Self::SendFuture<'_>;
104+
/// Return type of the [`.send()`] method
100105
type SendFuture<'a>: Future<Output = Result<(), Self::Error>>
101106
where
102107
Self: 'a;
@@ -109,9 +114,11 @@ pub trait UnconnectedUdp {
109114
///
110115
/// The local and remote address are given, in that order, in the result along with the number
111116
/// of bytes.
112-
fn receive(&mut self, buffer: &mut [u8]) -> Self::ReceiveFuture<'_>;
113-
type ReceiveFuture<'a>: Future<Output = Result<(usize, SocketAddr, SocketAddr), Self::Error>>
114-
where
117+
fn receive_into(&mut self, buffer: &mut [u8]) -> Self::ReceiveIntoFuture<'_>;
118+
/// Return type of the [`.receive_into()`] method
119+
type ReceiveIntoFuture<'a>: Future<
120+
Output = Result<(usize, SocketAddr, SocketAddr), Self::Error>,
121+
> where
115122
Self: 'a;
116123
}
117124

@@ -124,12 +131,15 @@ pub trait UdpStack {
124131
/// Error type returned on socket creation failure.
125132
type Error: embedded_io::Error;
126133

134+
/// Eventual socket return type of the [`.connect()`] method
127135
type Connected<'m>: ConnectedUdp
128136
where
129137
Self: 'm;
138+
/// Eventual socket return type of the [`.bind_single()`] method
130139
type Bound<'m>: UnconnectedUdp
131140
where
132141
Self: 'm;
142+
/// Eventual return type of the [`.bind_multiple()`] method
133143
type Unbound<'m>: UnconnectedUdp
134144
where
135145
Self: 'm;
@@ -140,8 +150,9 @@ pub trait UdpStack {
140150
///
141151
/// While asynchronous traits implemented through GAT can not have provided default methods,
142152
/// implementers are encouraged to use the hidden `.connect_default()` method if all they would
143-
/// do is delegating to [`connect_from`] with a suitable unspecified local address.
153+
/// do is delegating to [`.connect_from`] with a suitable unspecified local address.
144154
fn connect(&self, remote: SocketAddr) -> Self::ConnectFuture<'_>;
155+
/// Future return type of the [`.connect()`] method
145156
type ConnectFuture<'a>: Future<Output = Result<(SocketAddr, Self::Connected<'a>), Self::Error>>
146157
where
147158
Self: 'a;
@@ -152,6 +163,7 @@ pub trait UdpStack {
152163
/// network stack at connection time. The full local address is returned along with the
153164
/// connected socket, primarily for debugging purposes.
154165
fn connect_from(&self, local: SocketAddr, remote: SocketAddr) -> Self::ConnectFromFuture<'_>;
166+
/// Future return type of the [`.connect_from()`] method
155167
type ConnectFromFuture<'a>: Future<
156168
Output = Result<(SocketAddr, Self::Connected<'a>), Self::Error>,
157169
> where
@@ -178,6 +190,7 @@ pub trait UdpStack {
178190
/// The full local address is returned along with the bound socket; it may then be passed on to
179191
/// other protocols for advertising purposes.
180192
fn bind_single(&self, local: SocketAddr) -> Self::BindSingleFuture<'_>;
193+
/// Future return type of the [`.bind_single()`] method
181194
type BindSingleFuture<'a>: Future<Output = Result<(SocketAddr, Self::Bound<'a>), Self::Error>>
182195
where
183196
Self: 'a;
@@ -205,6 +218,7 @@ pub trait UdpStack {
205218
/// binding to `[::]:0`, that is, picking some available port but then still leaving the
206219
/// interface and IP address unspecified.
207220
fn bind_multiple(&self, local: SocketAddr) -> Self::BindMultipleFuture<'_>;
221+
/// Future return type of the [`.bind_multiple()`] method
208222
type BindMultipleFuture<'a>: Future<Output = Result<Self::Unbound<'a>, Self::Error>>
209223
where
210224
Self: 'a;

0 commit comments

Comments
 (0)