From 734fc3ba2dcfaf79d2065b67d8c4282281744529 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Sun, 12 May 2024 14:22:11 -0400 Subject: [PATCH] code cleanup --- src/cache.rs | 26 +++++++++++++------------- src/lib.rs | 5 +---- src/messages.rs | 1 - 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/cache.rs b/src/cache.rs index a3dca46..465ce75 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -14,7 +14,10 @@ impl Cache { /// This should not be called directly. /// It is part of the MoreThanText::new function. pub fn new(rx: Receiver) -> Self { - Self { data: Vec::new(), rx: rx } + Self { + data: Vec::new(), + rx: rx, + } } /// Starts listening for database requests. @@ -32,17 +35,15 @@ impl Cache { fn get_session(&mut self, id: Option) -> ReceiveMsg { let sid: ReceiveMsg; match id { - Some(input) => { - match Uuid::parse_str(&input) { - Ok(vid) => { - if self.data.contains(&vid) { - sid = ReceiveMsg::Session(vid); - } else { - sid = self.new_session(); - } - }, - Err(_) => sid = self.new_session(), + Some(input) => match Uuid::parse_str(&input) { + Ok(vid) => { + if self.data.contains(&vid) { + sid = ReceiveMsg::Session(vid); + } else { + sid = self.new_session(); + } } + Err(_) => sid = self.new_session(), }, None => sid = self.new_session(), } @@ -103,8 +104,7 @@ mod session { let mut cache = Cache::new(rx); let id: Uuid; let bad_id = "A very bad id"; - match cache.get_session(Some(bad_id.to_string())) - { + match cache.get_session(Some(bad_id.to_string())) { ReceiveMsg::Session(sid) => id = sid, } assert_ne!(id.to_string(), bad_id); diff --git a/src/lib.rs b/src/lib.rs index 5111cb3..a119f4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,10 +51,7 @@ impl MoreThanText { /// ``` pub fn open_session(&mut self, id: Option) { let (tx, rx) = channel(); - let request = SessionRequest { - id: id, - tx: tx, - }; + let request = SessionRequest { id: id, tx: tx }; self.tx.send(SendMsg::OpenSession(request)).unwrap(); match rx.recv().unwrap() { ReceiveMsg::Session(sid) => self.id = Some(sid), diff --git a/src/messages.rs b/src/messages.rs index cb0fff6..3675a0a 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -12,7 +12,6 @@ pub enum ReceiveMsg { Session(Uuid), } - /// Items needed for a session request. pub struct SessionRequest { /// Optional string reprosentation of the session id.