1use futures::{Future, Poll};
2use lapin::{Connect as LapinConnect, Connection, ConnectionPromise, Result};
3
4use crate::{
5    tcp::Identity, uri::AMQPUri, Channel, ConfirmationFuture, ConnectionProperties, Error,
6};
7
8#[derive(Clone)]
10#[deprecated(note = "use lapin instead")]
11pub struct Client {
12    conn: Connection,
13}
14
15impl Client {
16    #[deprecated(note = "use lapin instead")]
18    pub fn connect(uri: &str, options: ConnectionProperties) -> ClientFuture {
19        Connect::connect(uri, options, None)
20    }
21
22    #[deprecated(note = "use lapin instead")]
24    pub fn connect_with_identity(
25        uri: &str,
26        options: ConnectionProperties,
27        identity: Identity<'_, '_>,
28    ) -> ClientFuture {
29        Connect::connect(uri, options, Some(identity))
30    }
31
32    #[deprecated(note = "use lapin instead")]
34    pub fn connect_uri(uri: AMQPUri, options: ConnectionProperties) -> ClientFuture {
35        Connect::connect(uri, options, None)
36    }
37
38    #[deprecated(note = "use lapin instead")]
40    pub fn connect_uri_with_identity(
41        uri: AMQPUri,
42        options: ConnectionProperties,
43        identity: Identity<'_, '_>,
44    ) -> ClientFuture {
45        Connect::connect(uri, options, Some(identity))
46    }
47
48    #[deprecated(note = "use lapin instead")]
50    pub fn create_channel(&self) -> impl Future<Item = Channel, Error = Error> + Send + 'static {
51        Channel::create(&self.conn)
52    }
53
54    #[deprecated(note = "use lapin instead")]
56    pub fn update_secret(&self, new_secret: &str, reason: &str) -> ConfirmationFuture<()> {
57        self.conn.update_secret(new_secret, reason).into()
58    }
59
60    #[deprecated(note = "use lapin instead")]
62    pub fn block(&self, reason: &str) -> ConfirmationFuture<()> {
63        self.conn.block(reason).into()
64    }
65
66    #[deprecated(note = "use lapin instead")]
68    pub fn unblock(&self) -> ConfirmationFuture<()> {
69        self.conn.unblock().into()
70    }
71
72    #[deprecated(note = "use lapin instead")]
74    pub fn on_error<E: Fn(Error) + Send + 'static>(&self, handler: Box<E>) {
75        self.conn.on_error(handler);
76    }
77}
78
79#[deprecated(note = "use lapin instead")]
80pub struct ClientFuture(ConfirmationFuture<Connection, Result<()>>);
81
82impl Future for ClientFuture {
83    type Item = Client;
84    type Error = Error;
85
86    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
87        Ok(self.0.poll()?.map(|conn| Client { conn }))
88    }
89}
90
91impl From<ConnectionPromise> for ClientFuture {
92    fn from(promise: ConnectionPromise) -> Self {
93        Self(promise.into())
94    }
95}
96
97#[deprecated(note = "use lapin instead")]
99pub trait Connect {
100    fn connect(
102        self,
103        options: ConnectionProperties,
104        identity: Option<Identity<'_, '_>>,
105    ) -> ClientFuture;
106}
107
108impl Connect for AMQPUri {
109    fn connect(
110        self,
111        options: ConnectionProperties,
112        identity: Option<Identity<'_, '_>>,
113    ) -> ClientFuture {
114        LapinConnect::connect(self, options, identity).into()
115    }
116}
117
118impl Connect for &str {
119    fn connect(
120        self,
121        options: ConnectionProperties,
122        identity: Option<Identity<'_, '_>>,
123    ) -> ClientFuture {
124        LapinConnect::connect(self, options, identity).into()
125    }
126}