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
use ntex::service::{IntoServiceFactory, ServiceFactory};

use super::connect::ConnectAck;

pub fn handshake<Io, St, A, F>(srv: F) -> Handshake<Io, St, A>
where
    F: IntoServiceFactory<A>,
    A: ServiceFactory<Config = (), Response = ConnectAck<Io, St>>,
{
    Handshake::new(srv)
}

pub struct Handshake<Io, St, A> {
    a: A,
    _t: std::marker::PhantomData<(Io, St)>,
}

impl<Io, St, A> Handshake<Io, St, A>
where
    A: ServiceFactory<Config = ()>,
{
    pub fn new<F>(srv: F) -> Handshake<Io, St, A>
    where
        F: IntoServiceFactory<A>,
    {
        Handshake {
            a: srv.into_factory(),
            _t: std::marker::PhantomData,
        }
    }
}

impl<Io, St, A> Handshake<Io, St, A>
where
    A: ServiceFactory<Config = (), Response = ConnectAck<Io, St>>,
{
    pub fn sasl<F, B>(self, srv: F) -> ntex::util::either::Either<A, B>
    where
        F: IntoServiceFactory<B>,
        B: ServiceFactory<
            Config = (),
            Response = A::Response,
            Error = A::Error,
            InitError = A::InitError,
        >,
        B::Error: Into<ntex_amqp_codec::protocol::Error>,
    {
        ntex::util::either(self.a, srv.into_factory())
    }
}