Merge pull request #657 from botika/master

Clean code at connect function
This commit is contained in:
Steven Fackler 2020-09-20 14:06:25 -04:00 committed by GitHub
commit cd31c02d77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,14 +25,15 @@ where
let mut error = None; let mut error = None;
for (i, host) in config.host.iter().enumerate() { for (i, host) in config.host.iter().enumerate() {
let port = *config let port = config
.port .port
.get(i) .get(i)
.or_else(|| config.port.get(0)) .or_else(|| config.port.get(0))
.unwrap_or(&5432); .copied()
.unwrap_or(5432);
let hostname = match host { let hostname = match host {
Host::Tcp(host) => &**host, Host::Tcp(host) => host.as_str(),
// postgres doesn't support TLS over unix sockets, so the choice here doesn't matter // postgres doesn't support TLS over unix sockets, so the choice here doesn't matter
#[cfg(unix)] #[cfg(unix)]
Host::Unix(_) => "", Host::Unix(_) => "",