1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use std::io;

pub trait AsyncEncoder<Item> {
    type Error: From<io::Error>;
    type EncodeFuture<'a>: std::future::Future<Output = Result<(), Self::Error>>
    where
        Self: 'a;

    fn encode<IO>(&mut self, item: Item, dst: &mut IO) -> Self::EncodeFuture<'_>;
}

pub trait AsyncDecoder {
    type Item;
    type Error: From<io::Error>;
    type DecodeFuture<'a>: std::future::Future<Output = Result<Option<Self::Item>, Self::Error>>
    where
        Self: 'a;

    fn decode<IO>(&mut self, src: &mut IO) -> Self::DecodeFuture<'_>;
}