1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#![deny(missing_docs, rust_2018_idioms, unused, unused_crate_dependencies, unused_import_braces, unused_lifetimes, unused_qualifications, warnings)]
#![forbid(unsafe_code)]
use {
std::{
future::Future,
io,
pin::Pin,
},
tokio::io::{
AsyncRead,
AsyncWrite,
},
};
#[cfg(feature = "blocking")] use std::io::prelude::*;
pub use async_proto_derive::Protocol;
#[doc(hidden)] pub use {
derive_more,
tokio,
};
pub mod impls;
pub trait Protocol: Sized {
type ReadError;
fn read<'a, R: AsyncRead + Unpin + Send + 'a>(stream: R) -> Pin<Box<dyn Future<Output = Result<Self, Self::ReadError>> + Send + 'a>>;
fn write<'a, W: AsyncWrite + Unpin + Send + 'a>(&'a self, sink: W) -> Pin<Box<dyn Future<Output = io::Result<()>> + Send + 'a>>;
#[cfg(feature = "blocking")]
fn read_sync<'a>(stream: impl Read + 'a) -> Result<Self, Self::ReadError>;
#[cfg(feature = "blocking")]
fn write_sync<'a>(&self, sink: impl Write + 'a) -> io::Result<()>;
}