use std::io::Error;
use std::pin::Pin;
use std::sync::Arc;
use bytes::Bytes;
#[cfg(feature = "pipe")]
#[cfg_attr(docsrs, doc(cfg(feature = "pipe")))]
pub mod pipe;
#[cfg(feature = "websocket")]
#[cfg_attr(docsrs, doc(cfg(feature = "websocket")))]
pub mod websocket;
pub type IoFuture<'a, T> = Pin<Box<dyn Future<Output = Result<T, Error>> + Send + 'a>>;
pub trait IpcListener: Send + Sync + 'static {
fn local_endpoint(&self) -> &str;
fn accept(&self) -> IoFuture<'_, Box<dyn IpcConnection>>;
}
pub trait IpcConnection: Send + Sync + 'static {
fn connect(endpoint: &str) -> impl Future<Output = Result<Self, Error>> + Send
where
Self: Sized;
fn peer_endpoint(&self) -> &str;
fn close(&mut self) -> IoFuture<'_, ()>;
fn send(&mut self, buf: Bytes) -> IoFuture<'_, ()>;
fn recv(&mut self) -> IoFuture<'_, Bytes>;
}
impl<T> IpcListener for Box<T>
where
T: IpcListener + ?Sized,
{
fn local_endpoint(&self) -> &str {
(**self).local_endpoint()
}
fn accept(&self) -> IoFuture<'_, Box<dyn IpcConnection>> {
(**self).accept()
}
}
impl<T> IpcListener for Arc<T>
where
T: IpcListener + ?Sized,
{
fn local_endpoint(&self) -> &str {
(**self).local_endpoint()
}
fn accept(&self) -> IoFuture<'_, Box<dyn IpcConnection>> {
(**self).accept()
}
}