Add AsyncStreamProtocol trait with subtraits

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/18/head
trivernis 3 years ago
parent f35908815c
commit b55c6e526b
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

12
Cargo.lock generated

@ -2,6 +2,17 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "async-trait"
version = "0.1.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44318e776df68115a881de9a8fd1b9e53368d7a4a5ce4cc48517da3393233a5e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "atty"
version = "0.2.14"
@ -502,6 +513,7 @@ dependencies = [
name = "rmp-ipc"
version = "0.8.2"
dependencies = [
"async-trait",
"byteorder",
"criterion",
"lazy_static",

@ -26,6 +26,7 @@ tracing = "0.1.29"
lazy_static = "1.4.0"
typemap_rev = "0.1.5"
byteorder = "1.4.3"
async-trait = "0.1.51"
[dependencies.serde]
version = "1.0.130"

@ -105,6 +105,7 @@ mod events;
pub mod ipc;
mod macros;
mod namespaces;
pub(crate) mod protocol;
pub use events::error_event;
pub use events::event;

@ -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…
Cancel
Save