#![allow(private_bounds)]
use {
crate::{
bound_util::{RefTokioAsyncRead, RefTokioAsyncWrite},
local_socket::{traits::StreamCommon, ConnectOptions, Name},
Sealed,
},
std::{future::Future, io},
tokio::io::{AsyncRead, AsyncWrite},
};
pub trait Stream:
AsyncRead + RefTokioAsyncRead + AsyncWrite + RefTokioAsyncWrite + StreamCommon
{
type RecvHalf: RecvHalf<Stream = Self>;
type SendHalf: SendHalf<Stream = Self>;
fn connect(name: Name<'_>) -> impl Future<Output = io::Result<Self>> + Send + Sync {
async { ConnectOptions::new().name(name).connect_tokio_as::<Self>().await }
}
fn split(self) -> (Self::RecvHalf, Self::SendHalf);
fn reunite(rh: Self::RecvHalf, sh: Self::SendHalf) -> ReuniteResult<Self>;
fn from_options(
options: &ConnectOptions<'_>,
) -> impl Future<Output = io::Result<Self>> + Send + Sync;
}
pub trait RecvHalf:
AsyncRead + RefTokioAsyncRead + Send + Sync + Sized + Sealed + 'static
{
type Stream: Stream;
}
pub trait SendHalf:
AsyncWrite + RefTokioAsyncWrite + Send + Sync + Sized + Sealed + 'static
{
type Stream: Stream;
}
pub type ReuniteResult<S> =
crate::error::ReuniteResult<S, <S as Stream>::RecvHalf, <S as Stream>::SendHalf>;