Skip to content

Commit 5cd83b8

Browse files
committed
async UDP: Documentation fixes; receive_into consistency
One trait's receive_into still used the old receive name.
1 parent 9cb3e89 commit 5cd83b8

File tree

1 file changed

+17
-4
lines changed
  • embedded-nal-async/src/stack

1 file changed

+17
-4
lines changed

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

Lines changed: 17 additions & 4 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>> where Self: 'a;
3537

3638
/// Receive a datagram into the provided buffer.
@@ -45,6 +47,7 @@ pub trait ConnectedUdp {
4547
/// (a possibility not considered there). The name deviates from the original `receive()` to
4648
/// make room for a version that is more zero-copy friendly.
4749
fn receive_into(&mut self, buffer: &mut [u8]) -> Self::ReceiveIntoFuture<'_>;
50+
/// Return type of the [`.receive_into()`] method
4851
type ReceiveIntoFuture<'a>: Future<Output = Result<usize, Self::Error>> where Self: 'a;
4952

5053
// WIP to allow zero-copy operation
@@ -67,6 +70,7 @@ pub trait ConnectedUdp {
6770
/// caller MUST pass in the same (or compatible) values, MAY and pass in unspecified values where
6871
/// applicable. The implementer MAY check them for compatibility, and SHOULD do that in debug mode.
6972
pub trait UnconnectedUdp {
73+
/// Error type returned by send and receive operations.
7074
type Error: embedded_io::Error;
7175

7276
/// Send the provided data to a peer
@@ -86,13 +90,14 @@ pub trait UnconnectedUdp {
8690
/// address. Both are valid choices in some situations, and the right choice depends on the
8791
/// protocol used.
8892
///
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
9094
/// in that single address -- even though they've made their intention clear at construction.
9195
/// They can pass either the one obtained at socket creation time, or the one obtained at
9296
/// receive time; these should be equal. This allows implementations of the trait to use a
9397
/// single kind of socket for both sockets bound to a single and sockets bound to multiple
9498
/// addresses.
9599
fn send(&mut self, local: SocketAddr, remote: SocketAddr, data: &[u8]) -> Self::SendFuture<'_>;
100+
/// Return type of the [`.send()`] method
96101
type SendFuture<'a>: Future<Output = Result<(), Self::Error>> where Self: 'a;
97102

98103
/// Receive a datagram into the provided buffer.
@@ -103,8 +108,9 @@ pub trait UnconnectedUdp {
103108
///
104109
/// The local and remote address are given, in that order, in the result along with the number
105110
/// 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;
108114
}
109115

110116
/// This trait is implemented by UDP/IP stacks. The trait allows the underlying driver to
@@ -116,8 +122,11 @@ pub trait UdpStack {
116122
/// Error type returned on socket creation failure.
117123
type Error: embedded_io::Error;
118124

125+
/// Eventual socket return type of the [`.connect()`] method
119126
type Connected<'m>: ConnectedUdp where Self: 'm;
127+
/// Eventual socket return type of the [`.bind_single()`] method
120128
type Bound<'m>: UnconnectedUdp where Self: 'm;
129+
/// Eventual return type of the [`.bind_multiple()`] method
121130
type Unbound<'m>: UnconnectedUdp where Self: 'm;
122131

123132
/// Create a socket that has a fixed remote address.
@@ -126,8 +135,9 @@ pub trait UdpStack {
126135
///
127136
/// While asynchronous traits implemented through GAT can not have provided default methods,
128137
/// 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.
130139
fn connect(&self, remote: SocketAddr) -> Self::ConnectFuture<'_>;
140+
/// Future return type of the [`.connect()`] method
131141
type ConnectFuture<'a>: Future<Output = Result<(SocketAddr, Self::Connected<'a>), Self::Error>> where Self: 'a;
132142

133143
/// Create a socket that has a fixed remote address.
@@ -136,6 +146,7 @@ pub trait UdpStack {
136146
/// network stack at connection time. The full local address is returned along with the
137147
/// connected socket, primarily for debugging purposes.
138148
fn connect_from(&self, local: SocketAddr, remote: SocketAddr) -> Self::ConnectFromFuture<'_>;
149+
/// Future return type of the [`.connect_from()`] method
139150
type ConnectFromFuture<'a>: Future<Output = Result<(SocketAddr, Self::Connected<'a>), Self::Error>> where Self: 'a;
140151

141152
/// Helper that implements [`connect()`] using [`connect_from()`].
@@ -159,6 +170,7 @@ pub trait UdpStack {
159170
/// The full local address is returned along with the bound socket; it may then be passed on to
160171
/// other protocols for advertising purposes.
161172
fn bind_single(&self, local: SocketAddr) -> Self::BindSingleFuture<'_>;
173+
/// Future return type of the [`.bind_single()`] method
162174
type BindSingleFuture<'a>: Future<Output = Result<(SocketAddr, Self::Bound<'a>), Self::Error>> where Self: 'a;
163175

164176
/// Create a socket that has no single fixed local address.
@@ -184,5 +196,6 @@ pub trait UdpStack {
184196
/// binding to `[::]:0`, that is, picking some available port but then still leaving the
185197
/// interface and IP address unspecified.
186198
fn bind_multiple(&self, local: SocketAddr) -> Self::BindMultipleFuture<'_>;
199+
/// Future return type of the [`.bind_multiple()`] method
187200
type BindMultipleFuture<'a>: Future<Output = Result<Self::Unbound<'a>, Self::Error>> where Self: 'a;
188201
}

0 commit comments

Comments
 (0)