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
#![deny(missing_docs)]
#![warn(rust_2018_idioms)]
#![doc(html_root_url = "https://docs.rs/amq-protocol-tcp/6.0.0-alpha6/")]
use amq_protocol_uri::{AMQPScheme, AMQPUri};
use log::trace;
pub use tcp_stream::{HandshakeResult, Identity, TcpStream};
pub trait AMQPUriTcpExt {
fn connect(&self) -> HandshakeResult
where
Self: Sized,
{
self.connect_with_identity(None)
}
fn connect_with_identity(&self, identity: Option<Identity<'_, '_>>) -> HandshakeResult;
}
impl AMQPUriTcpExt for AMQPUri {
fn connect_with_identity(&self, identity: Option<Identity<'_, '_>>) -> HandshakeResult {
let uri = format!("{}:{}", self.authority.host, self.authority.port);
trace!("Connecting to {}", uri);
let stream = TcpStream::connect(uri)?;
match self.scheme {
AMQPScheme::AMQP => Ok(stream),
AMQPScheme::AMQPS => stream.into_tls(&self.authority.host, identity),
}
}
}