use core::net::SocketAddr;
use embedded_io_async::ErrorType;
use crate::udp::{UdpReceive, UdpSend};
use crate::{MulticastV4, MulticastV6, Readable};
pub trait UdpSplit: ErrorType {
type Receive<'a>: UdpReceive<Error = Self::Error> + Readable<Error = Self::Error>
where
Self: 'a;
type Send<'a>: UdpSend<Error = Self::Error>
where
Self: 'a;
fn split(&mut self) -> (Self::Receive<'_>, Self::Send<'_>);
}
impl<T> UdpSplit for &mut T
where
T: UdpSplit,
{
type Receive<'a>
= T::Receive<'a>
where
Self: 'a;
type Send<'a>
= T::Send<'a>
where
Self: 'a;
fn split(&mut self) -> (Self::Receive<'_>, Self::Send<'_>) {
(**self).split()
}
}
pub trait UdpConnect {
type Error: embedded_io_async::Error;
type Socket<'a>: UdpReceive<Error = Self::Error>
+ UdpSend<Error = Self::Error>
+ UdpSplit<Error = Self::Error>
+ MulticastV4<Error = Self::Error>
+ MulticastV6<Error = Self::Error>
+ Readable<Error = Self::Error>
where
Self: 'a;
async fn connect(
&self,
local: SocketAddr,
remote: SocketAddr,
) -> Result<Self::Socket<'_>, Self::Error>;
}
pub trait UdpBind {
type Error: embedded_io_async::Error;
type Socket<'a>: UdpReceive<Error = Self::Error>
+ UdpSend<Error = Self::Error>
+ UdpSplit<Error = Self::Error>
+ MulticastV4<Error = Self::Error>
+ MulticastV6<Error = Self::Error>
+ Readable<Error = Self::Error>
where
Self: 'a;
async fn bind(&self, local: SocketAddr) -> Result<Self::Socket<'_>, Self::Error>;
}
impl<T> UdpConnect for &T
where
T: UdpConnect,
{
type Error = T::Error;
type Socket<'a>
= T::Socket<'a>
where
Self: 'a;
async fn connect(
&self,
local: SocketAddr,
remote: SocketAddr,
) -> Result<Self::Socket<'_>, Self::Error> {
(*self).connect(local, remote).await
}
}
impl<T> UdpConnect for &mut T
where
T: UdpConnect,
{
type Error = T::Error;
type Socket<'a>
= T::Socket<'a>
where
Self: 'a;
async fn connect(
&self,
local: SocketAddr,
remote: SocketAddr,
) -> Result<Self::Socket<'_>, Self::Error> {
(**self).connect(local, remote).await
}
}
impl<T> UdpBind for &T
where
T: UdpBind,
{
type Error = T::Error;
type Socket<'a>
= T::Socket<'a>
where
Self: 'a;
async fn bind(&self, local: SocketAddr) -> Result<Self::Socket<'_>, Self::Error> {
(*self).bind(local).await
}
}
impl<T> UdpBind for &mut T
where
T: UdpBind,
{
type Error = T::Error;
type Socket<'a>
= T::Socket<'a>
where
Self: 'a;
async fn bind(&self, local: SocketAddr) -> Result<Self::Socket<'_>, Self::Error> {
(**self).bind(local).await
}
}