Skip to content

Commit 4db1bc8

Browse files
authored
Merge pull request #22 from dimacurrentai/main
Less ugliness. Disclaimer: I do not have a good intuition on what is possible and what is Rusty. Yet.
2 parents c3f3dd4 + d8a3260 commit 4db1bc8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

step07_redb/code/src/main.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,9 @@ async fn inc_counter(redb: &Database, idx: u64) -> Result<u64, Box<dyn Error>> {
5050
Ok(counter_runs)
5151
}
5252

53-
async fn run_main(redb: Arc<Database>, initial_counter_runs_value: u64) {
53+
async fn run_main(redb: Arc<Database>, counter_runs: u64) {
5454
let (shutdown_tx, mut shutdown_rx) = mpsc::channel::<()>(1);
5555

56-
let counter_runs = Arc::new(initial_counter_runs_value);
57-
5856
let app = Router::new()
5957
.route("/healthz", get(|| async { "OK\n" }))
6058
.route("/", get(|| async { "hello this is a rust http server\n" }))
@@ -70,12 +68,14 @@ async fn run_main(redb: Arc<Database>, initial_counter_runs_value: u64) {
7068
)
7169
.route(
7270
"/json",
73-
get(|headers: HeaderMap| async move {
74-
let counter_runs = *counter_runs;
75-
let counter_requests = inc_counter(&redb, 2).await.unwrap_or(0);
76-
let response = JSONResponse::Counters { counter_runs, counter_requests };
77-
let json_string = serde_json::to_string(&response).unwrap();
78-
http::json_or_html(headers, &json_string).await
71+
get(move |headers: HeaderMap| {
72+
let counter_runs = counter_runs;
73+
async move {
74+
let counter_requests = inc_counter(&redb, 2).await.unwrap_or(0);
75+
let response = JSONResponse::Counters { counter_runs, counter_requests };
76+
let json_string = serde_json::to_string(&response).unwrap();
77+
http::json_or_html(headers, &json_string).await
78+
}
7979
}),
8080
);
8181

0 commit comments

Comments
 (0)