mirror of https://github.com/Trivernis/bromine.git
Add AsyncStreamProtocol trait with subtraits
Signed-off-by: trivernis <trivernis@protonmail.com>pull/18/head
parent
f35908815c
commit
b55c6e526b
@ -0,0 +1,31 @@
|
||||
use crate::prelude::IPCResult;
|
||||
use async_trait::async_trait;
|
||||
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;
|
||||
|
||||
async fn bind(address: Self::AddressType) -> IPCResult<Self>;
|
||||
|
||||
async fn accept(&self) -> IPCResult<(Self::Stream, Self::RemoteAddressType)>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait AsyncProtocolStream: AsyncRead + AsyncWrite + Sized + Send + Sync {
|
||||
type AddressType;
|
||||
type OwnedSplitReadHalf: AsyncRead + Send + Sync;
|
||||
type OwnedSplitWriteHalf: AsyncWrite + Send + Sync;
|
||||
|
||||
async fn connect(address: Self::AddressType) -> IPCResult<Self>;
|
||||
|
||||
async fn into_split(self) -> IPCResult<(Self::OwnedSplitReadHalf, Self::OwnedSplitWriteHalf)>;
|
||||
}
|
Loading…
Reference in New Issue