contained_core/connect/
mod.rs1pub use self::{connection::*, frame::*};
7
8mod connection;
9mod frame;
10
11use async_trait::async_trait;
12use bytes::Buf;
13use tokio::net::ToSocketAddrs;
14
15pub trait TokioFrame {
16 type Error;
17 fn check(buf: &mut impl Buf) -> Result<(), Self::Error>;
18 fn parse(buf: &mut impl Buf) -> Result<Self, Self::Error>
19 where
20 Self: Sized;
21}
22
23#[async_trait]
24pub trait AsyncConnection<Frame: TokioFrame> {
25 type Error: Send + Sync;
26
27 async fn connect(addr: impl ToSocketAddrs) -> Result<Self, Self::Error>
28 where
29 Self: Sized;
30 fn read(&mut self) -> Result<Option<Frame>, Self::Error>;
31 async fn write(&mut self, frame: &Frame) -> Result<(), Self::Error>;
32}