diff --git a/tokio-postgres-native-tls/src/lib.rs b/tokio-postgres-native-tls/src/lib.rs index d792ba01..cebfe556 100644 --- a/tokio-postgres-native-tls/src/lib.rs +++ b/tokio-postgres-native-tls/src/lib.rs @@ -60,11 +60,11 @@ where fn poll(&mut self) -> Poll<(TlsStream, ChannelBinding), native_tls::Error> { let stream = try_ready!(self.0.poll()); - let mut channel_binding = ChannelBinding::new(); - if let Some(buf) = stream.get_ref().tls_server_end_point().unwrap_or(None) { - channel_binding = channel_binding.tls_server_end_point(buf); - } + let channel_binding = match stream.get_ref().tls_server_end_point().unwrap_or(None) { + Some(buf) => ChannelBinding::tls_server_end_point(buf), + None => ChannelBinding::none(), + }; Ok(Async::Ready((stream, channel_binding))) } diff --git a/tokio-postgres-openssl/src/lib.rs b/tokio-postgres-openssl/src/lib.rs index f3b72f0a..802ee0ad 100644 --- a/tokio-postgres-openssl/src/lib.rs +++ b/tokio-postgres-openssl/src/lib.rs @@ -60,10 +60,10 @@ where fn poll(&mut self) -> Poll<(SslStream, ChannelBinding), HandshakeError> { let stream = try_ready!(self.0.poll()); - let mut channel_binding = ChannelBinding::new(); - if let Some(buf) = tls_server_end_point(stream.get_ref().ssl()) { - channel_binding = channel_binding.tls_server_end_point(buf); - } + let channel_binding = match tls_server_end_point(stream.get_ref().ssl()) { + Some(buf) => ChannelBinding::tls_server_end_point(buf), + None => ChannelBinding::none(), + }; Ok(Async::Ready((stream, channel_binding))) } diff --git a/tokio-postgres/src/tls.rs b/tokio-postgres/src/tls.rs index fc7e8233..30ea8e16 100644 --- a/tokio-postgres/src/tls.rs +++ b/tokio-postgres/src/tls.rs @@ -12,15 +12,16 @@ pub struct ChannelBinding { } impl ChannelBinding { - pub fn new() -> ChannelBinding { + pub fn none() -> ChannelBinding { ChannelBinding { tls_server_end_point: None, } } - pub fn tls_server_end_point(mut self, tls_server_end_point: Vec) -> ChannelBinding { - self.tls_server_end_point = Some(tls_server_end_point); - self + pub fn tls_server_end_point(tls_server_end_point: Vec) -> ChannelBinding { + ChannelBinding { + tls_server_end_point: Some(tls_server_end_point), + } } } @@ -60,7 +61,7 @@ where fn handle_tls(self, use_tls: bool, stream: S) -> FutureResult<(S, ChannelBinding), Void> { debug_assert!(!use_tls); - future::ok((stream, ChannelBinding::new())) + future::ok((stream, ChannelBinding::none())) } } @@ -113,7 +114,7 @@ where } PreferTlsFutureInner::Raw(s) => Ok(Async::Ready(( MaybeTlsStream::Raw(s.take().expect("future polled after completion")), - ChannelBinding::new(), + ChannelBinding::none(), ))), } }