actix_amqp/server/
handshake.rs

1use actix_service::{IntoServiceFactory, ServiceFactory};
2
3use super::connect::ConnectAck;
4
5pub fn handshake<Io, St, A, F>(srv: F) -> Handshake<Io, St, A>
6where
7    F: IntoServiceFactory<A>,
8    A: ServiceFactory<Config = (), Response = ConnectAck<Io, St>>,
9{
10    Handshake::new(srv)
11}
12
13pub struct Handshake<Io, St, A> {
14    a: A,
15    _t: std::marker::PhantomData<(Io, St)>,
16}
17
18impl<Io, St, A> Handshake<Io, St, A>
19where
20    A: ServiceFactory<Config = ()>,
21{
22    pub fn new<F>(srv: F) -> Handshake<Io, St, A>
23    where
24        F: IntoServiceFactory<A>,
25    {
26        Handshake {
27            a: srv.into_factory(),
28            _t: std::marker::PhantomData,
29        }
30    }
31}
32
33impl<Io, St, A> Handshake<Io, St, A>
34where
35    A: ServiceFactory<Config = (), Response = ConnectAck<Io, St>>,
36{
37    pub fn sasl<F, B>(self, srv: F) -> actix_utils::either::Either<A, B>
38    where
39        F: IntoServiceFactory<B>,
40        B: ServiceFactory<
41            Config = (),
42            Response = A::Response,
43            Error = A::Error,
44            InitError = A::InitError,
45        >,
46        B::Error: Into<amqp_codec::protocol::Error>,
47    {
48        actix_utils::either::Either::new(self.a, srv.into_factory())
49    }
50}