From f966feb0e108e5a40487844a29ec4ecb69ec425d Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Sat, 9 Nov 2024 12:45:19 -0500 Subject: [PATCH] Moved record to data. --- src/{record => data}/id.rs | 0 src/{record => data}/mod.rs | 9 ++------- src/lib.rs | 20 ++++++++------------ src/router.rs | 2 +- src/session.rs | 26 ++++++++++++++------------ 5 files changed, 25 insertions(+), 32 deletions(-) rename src/{record => data}/id.rs (100%) rename src/{record => data}/mod.rs (93%) diff --git a/src/record/id.rs b/src/data/id.rs similarity index 100% rename from src/record/id.rs rename to src/data/id.rs diff --git a/src/record/mod.rs b/src/data/mod.rs similarity index 93% rename from src/record/mod.rs rename to src/data/mod.rs index 274a013..3ed5f54 100644 --- a/src/record/mod.rs +++ b/src/data/mod.rs @@ -1,10 +1,7 @@ mod id; use id::ID; -use std::{ - collections::HashMap, - fmt, -}; +use std::{collections::HashMap, fmt}; #[derive(Clone)] enum Field { @@ -17,9 +14,7 @@ struct Record { impl Record { fn new(data: HashMap) -> Self { - Self { - data: data, - } + Self { data: data } } fn len(&self) -> usize { diff --git a/src/lib.rs b/src/lib.rs index 1da36de..51bacf5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ mod client; -mod record; +mod data; mod message; mod router; mod session; @@ -8,9 +8,7 @@ use client::{Client, ClientMsg}; use message::{Message, MsgData}; use router::Router; use session::{Session, SessionData, SessionMsg}; -use std::{ - sync::mpsc::{channel, Sender}, -}; +use std::sync::mpsc::{channel, Sender}; /// Support functions for Messages. pub trait Msg { @@ -84,13 +82,11 @@ impl MoreThanText { let msg = Message::new(&req); self.tx.send(msg).unwrap(); match rx.recv().unwrap().get_message() { - MsgData::Session(data) => { - match data { - SessionMsg::Opened(sess) => self.session = Some(sess.clone()), - _ => {}, - } + MsgData::Session(data) => match data { + SessionMsg::Opened(sess) => self.session = Some(sess.clone()), + _ => {} }, - _ => {}, + _ => {} }; } @@ -115,8 +111,8 @@ impl MoreThanText { impl Clone for MoreThanText { fn clone(&self) -> Self { Self { - session: None, - tx: self.tx.clone(), + session: None, + tx: self.tx.clone(), } } } diff --git a/src/router.rs b/src/router.rs index 0ca85cd..a31cf68 100644 --- a/src/router.rs +++ b/src/router.rs @@ -36,9 +36,9 @@ impl Router { #[cfg(test)] mod messages { - use std::sync::mpsc::channel; use super::super::MsgData; use super::{super::test_message::Tester, *}; + use std::sync::mpsc::channel; #[test] fn forward_messages() { diff --git a/src/session.rs b/src/session.rs index 85148f9..a10f69e 100644 --- a/src/session.rs +++ b/src/session.rs @@ -67,23 +67,21 @@ impl Session { SessionMsg::Get(req_id) => { let id: Uuid; match req_id { - Some(req) => { - match Uuid::try_parse(req) { - Ok(data) => { - if self.ids.contains(&data) { - id = data; - } else { - id = self.create_session(); - } - }, - Err(_) => id = self.create_session(), + Some(req) => match Uuid::try_parse(req) { + Ok(data) => { + if self.ids.contains(&data) { + id = data; + } else { + id = self.create_session(); + } } + Err(_) => id = self.create_session(), }, None => id = self.create_session(), } let data = SessionMsg::Opened(SessionData::new(id)); self.router_tx.send(msg.reply(&data)).unwrap() - }, + } _ => {} }, _ => {} @@ -229,7 +227,11 @@ mod messages { assert_eq!(result.get_id(), msg.get_id()); match result.get_message() { MsgData::Session(data) => match data { - SessionMsg::Opened(sess) => assert_eq!(sess.to_string(), thesess.to_string(), "Should use existing sesssion."), + SessionMsg::Opened(sess) => assert_eq!( + sess.to_string(), + thesess.to_string(), + "Should use existing sesssion." + ), _ => unreachable!("Should habe been an Opened message."), }, _ => unreachable!("Should have been a session message."),