Moved record to data.
Some checks failed
MoreThanText/morethantext/pipeline/head There was a failure building this commit
Some checks failed
MoreThanText/morethantext/pipeline/head There was a failure building this commit
This commit is contained in:
parent
4b836e453d
commit
f966feb0e1
@ -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<String, Field>) -> Self {
|
||||
Self {
|
||||
data: data,
|
||||
}
|
||||
Self { data: data }
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
20
src/lib.rs
20
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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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."),
|
||||
|
Loading…
Reference in New Issue
Block a user