#![allow(private_bounds)]
use {
crate::{
bound_util::{RefRead, RefWrite},
local_socket::{ConnectOptions, Name, PeerCreds},
Sealed,
},
std::{
fmt::Debug,
io::{self, prelude::*},
time::Duration,
},
};
pub trait Stream: Read + RefRead + Write + RefWrite + StreamCommon {
type RecvHalf: RecvHalf<Stream = Self>;
type SendHalf: SendHalf<Stream = Self>;
#[inline]
fn connect(name: Name<'_>) -> io::Result<Self> {
ConnectOptions::new().name(name).connect_sync_as::<Self>()
}
fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()>;
fn set_recv_timeout(&self, timeout: Option<Duration>) -> io::Result<()>;
fn set_send_timeout(&self, timeout: Option<Duration>) -> io::Result<()>;
fn split(self) -> (Self::RecvHalf, Self::SendHalf);
fn reunite(rh: Self::RecvHalf, sh: Self::SendHalf) -> ReuniteResult<Self>;
fn from_options(options: &ConnectOptions<'_>) -> io::Result<Self>;
}
pub trait StreamCommon: Debug + Send + Sync + Sized + Sealed + 'static {
fn take_error(&self) -> io::Result<Option<io::Error>>;
fn peer_creds(&self) -> io::Result<PeerCreds>;
}
pub trait RecvHalf: Read + RefRead + Send + Sync + Sized + Sealed + 'static {
type Stream: Stream;
fn set_timeout(&self, timeout: Option<Duration>) -> io::Result<()>;
}
pub trait SendHalf: Write + RefWrite + Send + Sync + Sized + Sealed + 'static {
type Stream: Stream;
fn set_timeout(&self, timeout: Option<Duration>) -> io::Result<()>;
}
pub type ReuniteResult<S> =
crate::error::ReuniteResult<S, <S as Stream>::RecvHalf, <S as Stream>::SendHalf>;