contained_core/connect/
mod.rs

1/*
2    Appellation: connect <module>
3    Contrib: FL03 <jo3mccain@icloud.com>
4    Description: ... summary ...
5*/
6pub 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}