Skip to content

Commit 435ccbe

Browse files
committed
Auto merge of #4165 - Turbo87:match-match, r=locks
bin/server: Simplify assignments via `match` This PR replaces two conditional assignments with `match` assignments to make the code a little less verbose. Semantically these instructions should be identical.
2 parents eda0d5a + 2e96571 commit 435ccbe

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/bin/server.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![warn(clippy::all, rust_2018_idioms)]
22

3-
use cargo_registry::{metrics::LogEncoder, util::errors::AppResult, App, Env};
3+
use cargo_registry::{env_optional, metrics::LogEncoder, util::errors::AppResult, App, Env};
44
use std::{env, fs::File, process::Command, sync::Arc, time::Duration};
55

66
use conduit_hyper::Service;
@@ -54,24 +54,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
5454
} else {
5555
[127, 0, 0, 1]
5656
};
57-
let port = if heroku {
58-
8888
59-
} else {
60-
dotenv::var("PORT")
61-
.ok()
62-
.and_then(|s| s.parse().ok())
63-
.unwrap_or(8888)
57+
let port = match (heroku, env_optional("PORT")) {
58+
(false, Some(port)) => port,
59+
_ => 8888,
6460
};
61+
6562
let threads = dotenv::var("SERVER_THREADS")
6663
.map(|s| s.parse().expect("SERVER_THREADS was not a valid number"))
67-
.unwrap_or_else(|_| {
68-
if env == Env::Development {
69-
5
70-
} else {
71-
// A large default because this can be easily changed via env and in production we
72-
// want the logging middleware to accurately record the start time.
73-
500
74-
}
64+
.unwrap_or_else(|_| match env {
65+
Env::Development => 5,
66+
// A large default because this can be easily changed via env and in production we
67+
// want the logging middleware to accurately record the start time.
68+
_ => 500,
7569
});
7670

7771
println!("Booting with a hyper based server");

0 commit comments

Comments
 (0)