use embedded_io_async::ErrorType;
use crate::raw::{RawReceive, RawSend};
use crate::Readable;
pub trait RawSplit: ErrorType {
type Receive<'a>: RawReceive<Error = Self::Error> + Readable<Error = Self::Error>
where
Self: 'a;
type Send<'a>: RawSend<Error = Self::Error>
where
Self: 'a;
fn split(&mut self) -> (Self::Receive<'_>, Self::Send<'_>);
}
impl<T> RawSplit for &mut T
where
T: RawSplit,
{
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 RawBind {
type Error: embedded_io_async::Error;
type Socket<'a>: RawReceive<Error = Self::Error>
+ RawSend<Error = Self::Error>
+ RawSplit<Error = Self::Error>
+ Readable<Error = Self::Error>
where
Self: 'a;
async fn bind(&self) -> Result<Self::Socket<'_>, Self::Error>;
}
impl<T> RawBind for &T
where
T: RawBind,
{
type Error = T::Error;
type Socket<'a>
= T::Socket<'a>
where
Self: 'a;
async fn bind(&self) -> Result<Self::Socket<'_>, Self::Error> {
(*self).bind().await
}
}
impl<T> RawBind for &mut T
where
T: RawBind,
{
type Error = T::Error;
type Socket<'a>
= T::Socket<'a>
where
Self: 'a;
async fn bind(&self) -> Result<Self::Socket<'_>, Self::Error> {
(**self).bind().await
}
}