mirror of https://github.com/Trivernis/bromine.git
Change all explicit protocols to generic trait bindings
Signed-off-by: trivernis <trivernis@protonmail.com>pull/18/head
parent
cff9b07e76
commit
4fe9ed16db
@ -1,33 +1,33 @@
|
||||
mod tcp;
|
||||
pub mod tcp;
|
||||
|
||||
use crate::prelude::IPCResult;
|
||||
use async_trait::async_trait;
|
||||
use std::fmt::Debug;
|
||||
use tokio::io::{AsyncRead, AsyncWrite};
|
||||
|
||||
#[async_trait]
|
||||
pub trait AsyncStreamProtocol {
|
||||
type Listener: AsyncStreamProtocolListener;
|
||||
type Stream: AsyncProtocolStream;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait AsyncStreamProtocolListener: Sized {
|
||||
type AddressType;
|
||||
type RemoteAddressType;
|
||||
type Stream: AsyncProtocolStream;
|
||||
type AddressType: ToString + Clone + Debug;
|
||||
type RemoteAddressType: ToString;
|
||||
type Stream: 'static + AsyncProtocolStream<AddressType = Self::AddressType>;
|
||||
|
||||
async fn protocol_bind(address: Self::AddressType) -> IPCResult<Self>;
|
||||
|
||||
async fn protocol_accept(&self) -> IPCResult<(Self::Stream, Self::RemoteAddressType)>;
|
||||
}
|
||||
|
||||
pub trait AsyncProtocolStreamSplit {
|
||||
type OwnedSplitReadHalf: AsyncRead + Send + Sync + Unpin;
|
||||
type OwnedSplitWriteHalf: AsyncWrite + Send + Sync + Unpin;
|
||||
|
||||
fn protocol_into_split(self) -> (Self::OwnedSplitReadHalf, Self::OwnedSplitWriteHalf);
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait AsyncProtocolStream: AsyncRead + AsyncWrite + Sized + Send + Sync {
|
||||
type AddressType;
|
||||
type OwnedSplitReadHalf: AsyncRead + Send + Sync;
|
||||
type OwnedSplitWriteHalf: AsyncWrite + Send + Sync;
|
||||
pub trait AsyncProtocolStream:
|
||||
AsyncRead + AsyncWrite + Sized + Send + Sync + AsyncProtocolStreamSplit
|
||||
{
|
||||
type AddressType: ToString + Clone + Debug;
|
||||
|
||||
async fn protocol_connect(address: Self::AddressType) -> IPCResult<Self>;
|
||||
|
||||
async fn protocol_into_split(self) -> (Self::OwnedSplitReadHalf, Self::OwnedSplitWriteHalf);
|
||||
}
|
||||
|
Loading…
Reference in New Issue