From c54403e6dc4829379e3d933f33da344c26fb7c1d Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Tue, 10 Oct 2023 17:08:19 -0700 Subject: [PATCH] server: Extract merge_message() --- server/src/main.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/src/main.rs b/server/src/main.rs index e7351db..bf4f4fc 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -80,6 +80,16 @@ impl Range { } } +fn merge_message(presses: &mut HashMap, message: Message) { + if let Some(r) = presses.get_mut(&message.key) { + if !r.contains(&message.t) { + r.extend(&message.t); + } + } else { + presses.insert(message.key, Range::new(&message.t)); + } +} + fn open_log_for_writing() -> csv::Writer { let log_file_exists = std::path::Path::new(LOGFILENAME).exists(); let logfile = std::fs::OpenOptions::new() @@ -110,13 +120,7 @@ fn main() { log.serialize((&message.key, message.t)) .expect("Couldn't write log"); log.flush().expect("Couldn't flush log"); - if let Some(r) = presses.get_mut(&message.key) { - if !r.contains(&message.t) { - r.extend(&message.t); - } - } else { - presses.insert(message.key, Range::new(&message.t)); - } + merge_message(&mut presses, message); } } } -- 2.44.1