From da89562800ccb48bb1823784fcf0c6405ee08561 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 2 Oct 2018 14:56:26 -0600 Subject: [PATCH] fix counter bug --- src/bin/main.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 4df7945..b3a9141 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -24,11 +24,6 @@ fn main() { let counter = Arc::clone(&counter); tasks.run(move || { - { - // in a subscope to release borrow automatically - let mut count = counter.lock().unwrap(); - *count += 1; - } handle_connection(counter, stream); }); } @@ -44,7 +39,8 @@ fn handle_connection(counter: Arc>, mut stream: TcpStream) { { // in a subscope to unlock automatically - let count = counter.lock().unwrap(); + let mut count = counter.lock().unwrap(); + *count += 1; println!("Request: {}\n{}", count, String::from_utf8_lossy(&buffer[..])); }