Skip to content

Commit

Permalink
async UDP: Better names for bound sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Sep 30, 2022
1 parent 74f9517 commit 82e1014
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions embedded-nal-async/src/stack/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
//! themselves UDP and --> may pretend to have performed some form of network address
//! translation, and present invalid addresses as the local address.
//!
//! * Implementing [`UdpStack::Bound`] and [`UdpStack::Unbound`] unconnected sockets separately
//! allows discarding the local addresses in the bound case. With LTO enabled, all the overhead
//! compared with a third trait variant between [ConnectedUdp] and [UnconnectedUdp] (in which the
//! local address is static but the remote address is flexible) should optimized out.
//! Implementing `Bound` and `Unbound` with the same type is expected to be a common choice.
//! * Implementing [`UdpStack::UniquelyBound`] and [`UdpStack::MultiplyBound`] unconnected sockets
//! separately allows discarding the local addresses in the bound case. With LTO enabled, all the
//! overhead compared with a third trait variant between [ConnectedUdp] and [UnconnectedUdp] (in
//! which the local address is static but the remote address is flexible) should optimized out.
//! Implementing `UniquelyBound` and `MultiplyBound` with the same type is expected to be a
//! common choice.
use core::future::Future;
use no_std_net::SocketAddr;
Expand Down Expand Up @@ -141,11 +142,11 @@ pub trait UdpStack {
where
Self: 'm;
/// Eventual socket return type of the [`.bind_single()`] method
type Bound<'m>: UnconnectedUdp
type UniquelyBound<'m>: UnconnectedUdp
where
Self: 'm;
/// Eventual return type of the [`.bind_multiple()`] method
type Unbound<'m>: UnconnectedUdp
type MultiplyBound<'m>: UnconnectedUdp
where
Self: 'm;

Expand Down Expand Up @@ -196,8 +197,9 @@ pub trait UdpStack {
/// other protocols for advertising purposes.
fn bind_single(&self, local: SocketAddr) -> Self::BindSingleFuture<'_>;
/// Future return type of the [`.bind_single()`] method
type BindSingleFuture<'a>: Future<Output = Result<(SocketAddr, Self::Bound<'a>), Self::Error>>
where
type BindSingleFuture<'a>: Future<
Output = Result<(SocketAddr, Self::UniquelyBound<'a>), Self::Error>,
> where
Self: 'a;

/// Create a socket that has no single fixed local address.
Expand All @@ -224,7 +226,7 @@ pub trait UdpStack {
/// interface and IP address unspecified.
fn bind_multiple(&self, local: SocketAddr) -> Self::BindMultipleFuture<'_>;
/// Future return type of the [`.bind_multiple()`] method
type BindMultipleFuture<'a>: Future<Output = Result<Self::Unbound<'a>, Self::Error>>
type BindMultipleFuture<'a>: Future<Output = Result<Self::MultiplyBound<'a>, Self::Error>>
where
Self: 'a;
}

0 comments on commit 82e1014

Please sign in to comment.