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
54
55
56
57
58
59
60
61
62
63
64
65
#![allow(missing_docs)]

use core::future::Future;

use crate::utils::{maybe, Error};

pub trait SendSpec: maybe::Send {
    type SendStream: crate::stream::Write;
}

pub trait RecvSpec: maybe::Send {
    type RecvStream: crate::stream::Read;
}

pub trait PairSpec: maybe::Send + SendSpec + RecvSpec {}

impl<T> PairSpec for T where T: maybe::Send + SendSpec + RecvSpec {}

pub type TupleFor<T> = (<T as SendSpec>::SendStream, <T as RecvSpec>::RecvStream);

pub trait OpeningBi: maybe::Send {
    type Streams: PairSpec;
    type Error: Error + maybe::Send + maybe::Sync + 'static;

    fn wait_bi(
        self,
    ) -> impl Future<Output = Result<TupleFor<Self::Streams>, Self::Error>> + maybe::Send;
}

pub trait OpenBi: PairSpec {
    type Opening: OpeningBi<Streams = Self>;
    type Error: Error + maybe::Send + maybe::Sync + 'static;

    fn open_bi(&self) -> impl Future<Output = Result<Self::Opening, Self::Error>> + maybe::Send;
}

pub trait AcceptBi: PairSpec {
    type Error: Error + maybe::Send + maybe::Sync + 'static;

    fn accept_bi(&self) -> impl Future<Output = Result<TupleFor<Self>, Self::Error>> + maybe::Send;
}

pub trait OpeningUni: maybe::Send {
    type Streams: SendSpec;
    type Error: Error + maybe::Send + maybe::Sync + 'static;

    fn wait_uni(
        self,
    ) -> impl Future<Output = Result<<Self::Streams as SendSpec>::SendStream, Self::Error>> + maybe::Send;
}

pub trait OpenUni: SendSpec {
    type Opening: OpeningUni<Streams = Self>;
    type Error: Error + maybe::Send + maybe::Sync + 'static;

    fn open_uni(&self) -> impl Future<Output = Result<Self::Opening, Self::Error>> + maybe::Send;
}

pub trait AcceptUni: RecvSpec {
    type Error: Error + maybe::Send + maybe::Sync + 'static;

    fn accept_uni(
        &self,
    ) -> impl Future<Output = Result<Self::RecvStream, Self::Error>> + maybe::Send;
}