Skip to content

Commit f58f4fd

Browse files
committed
async UDP: Fix lifetimes of send and receive functions
Elided lifetimes would have asked too little of the data / buffer references.
1 parent 776e6df commit f58f4fd

File tree

1 file changed

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

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub trait ConnectedUdp {
3131
type Error: embedded_io::Error;
3232

3333
/// Send the provided data to the connected peer
34-
fn send(&mut self, data: &[u8]) -> Self::SendFuture<'_>;
34+
fn send<'a>(&'a mut self, data: &'a [u8]) -> Self::SendFuture<'a>;
3535
/// Return type of the [`.send()`] method
3636
type SendFuture<'a>: Future<Output = Result<(), Self::Error>>
3737
where
@@ -48,7 +48,7 @@ pub trait ConnectedUdp {
4848
/// This deviates from the sync/nb equivalent trait in that it describes the overflow behavior
4949
/// (a possibility not considered there). The name deviates from the original `receive()` to
5050
/// make room for a version that is more zero-copy friendly.
51-
fn receive_into(&mut self, buffer: &mut [u8]) -> Self::ReceiveIntoFuture<'_>;
51+
fn receive_into<'a>(&'a mut self, buffer: &'a mut [u8]) -> Self::ReceiveIntoFuture<'a>;
5252
/// Return type of the [`.receive_into()`] method
5353
type ReceiveIntoFuture<'a>: Future<Output = Result<usize, Self::Error>>
5454
where
@@ -100,7 +100,12 @@ pub trait UnconnectedUdp {
100100
/// receive time; these should be equal. This allows implementations of the trait to use a
101101
/// single kind of socket for both sockets bound to a single and sockets bound to multiple
102102
/// addresses.
103-
fn send(&mut self, local: SocketAddr, remote: SocketAddr, data: &[u8]) -> Self::SendFuture<'_>;
103+
fn send<'a>(
104+
&'a mut self,
105+
local: SocketAddr,
106+
remote: SocketAddr,
107+
data: &'a [u8],
108+
) -> Self::SendFuture<'a>;
104109
/// Return type of the [`.send()`] method
105110
type SendFuture<'a>: Future<Output = Result<(), Self::Error>>
106111
where
@@ -114,7 +119,7 @@ pub trait UnconnectedUdp {
114119
///
115120
/// The local and remote address are given, in that order, in the result along with the number
116121
/// of bytes.
117-
fn receive_into(&mut self, buffer: &mut [u8]) -> Self::ReceiveIntoFuture<'_>;
122+
fn receive_into<'a>(&'a mut self, buffer: &'a mut [u8]) -> Self::ReceiveIntoFuture<'a>;
118123
/// Return type of the [`.receive_into()`] method
119124
type ReceiveIntoFuture<'a>: Future<
120125
Output = Result<(usize, SocketAddr, SocketAddr), Self::Error>,

0 commit comments

Comments
 (0)