X-Git-Url: http://git.scottworley.com/tattlekey/blobdiff_plain/5f5768318f897a20464ca177b5de64157afe0938..c54403e6dc4829379e3d933f33da344c26fb7c1d:/server/src/main.rs?ds=sidebyside 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); } } }