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;
|
mod id;
|
||||||
|
|
||||||
use id::ID;
|
use id::ID;
|
||||||
use std::{
|
use std::{collections::HashMap, fmt};
|
||||||
collections::HashMap,
|
|
||||||
fmt,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
enum Field {
|
enum Field {
|
||||||
@ -17,9 +14,7 @@ struct Record {
|
|||||||
|
|
||||||
impl Record {
|
impl Record {
|
||||||
fn new(data: HashMap<String, Field>) -> Self {
|
fn new(data: HashMap<String, Field>) -> Self {
|
||||||
Self {
|
Self { data: data }
|
||||||
data: data,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn len(&self) -> usize {
|
fn len(&self) -> usize {
|
14
src/lib.rs
14
src/lib.rs
@ -1,5 +1,5 @@
|
|||||||
mod client;
|
mod client;
|
||||||
mod record;
|
mod data;
|
||||||
mod message;
|
mod message;
|
||||||
mod router;
|
mod router;
|
||||||
mod session;
|
mod session;
|
||||||
@ -8,9 +8,7 @@ use client::{Client, ClientMsg};
|
|||||||
use message::{Message, MsgData};
|
use message::{Message, MsgData};
|
||||||
use router::Router;
|
use router::Router;
|
||||||
use session::{Session, SessionData, SessionMsg};
|
use session::{Session, SessionData, SessionMsg};
|
||||||
use std::{
|
use std::sync::mpsc::{channel, Sender};
|
||||||
sync::mpsc::{channel, Sender},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Support functions for Messages.
|
/// Support functions for Messages.
|
||||||
pub trait Msg {
|
pub trait Msg {
|
||||||
@ -84,13 +82,11 @@ impl MoreThanText {
|
|||||||
let msg = Message::new(&req);
|
let msg = Message::new(&req);
|
||||||
self.tx.send(msg).unwrap();
|
self.tx.send(msg).unwrap();
|
||||||
match rx.recv().unwrap().get_message() {
|
match rx.recv().unwrap().get_message() {
|
||||||
MsgData::Session(data) => {
|
MsgData::Session(data) => match data {
|
||||||
match data {
|
|
||||||
SessionMsg::Opened(sess) => self.session = Some(sess.clone()),
|
SessionMsg::Opened(sess) => self.session = Some(sess.clone()),
|
||||||
_ => {},
|
_ => {}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
_ => {},
|
_ => {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +36,9 @@ impl Router {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod messages {
|
mod messages {
|
||||||
use std::sync::mpsc::channel;
|
|
||||||
use super::super::MsgData;
|
use super::super::MsgData;
|
||||||
use super::{super::test_message::Tester, *};
|
use super::{super::test_message::Tester, *};
|
||||||
|
use std::sync::mpsc::channel;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn forward_messages() {
|
fn forward_messages() {
|
||||||
|
@ -67,23 +67,21 @@ impl Session {
|
|||||||
SessionMsg::Get(req_id) => {
|
SessionMsg::Get(req_id) => {
|
||||||
let id: Uuid;
|
let id: Uuid;
|
||||||
match req_id {
|
match req_id {
|
||||||
Some(req) => {
|
Some(req) => match Uuid::try_parse(req) {
|
||||||
match Uuid::try_parse(req) {
|
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
if self.ids.contains(&data) {
|
if self.ids.contains(&data) {
|
||||||
id = data;
|
id = data;
|
||||||
} else {
|
} else {
|
||||||
id = self.create_session();
|
id = self.create_session();
|
||||||
}
|
}
|
||||||
},
|
|
||||||
Err(_) => id = self.create_session(),
|
|
||||||
}
|
}
|
||||||
|
Err(_) => id = self.create_session(),
|
||||||
},
|
},
|
||||||
None => id = self.create_session(),
|
None => id = self.create_session(),
|
||||||
}
|
}
|
||||||
let data = SessionMsg::Opened(SessionData::new(id));
|
let data = SessionMsg::Opened(SessionData::new(id));
|
||||||
self.router_tx.send(msg.reply(&data)).unwrap()
|
self.router_tx.send(msg.reply(&data)).unwrap()
|
||||||
},
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -229,7 +227,11 @@ mod messages {
|
|||||||
assert_eq!(result.get_id(), msg.get_id());
|
assert_eq!(result.get_id(), msg.get_id());
|
||||||
match result.get_message() {
|
match result.get_message() {
|
||||||
MsgData::Session(data) => match data {
|
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 habe been an Opened message."),
|
||||||
},
|
},
|
||||||
_ => unreachable!("Should have been a session message."),
|
_ => unreachable!("Should have been a session message."),
|
||||||
|
Loading…
Reference in New Issue
Block a user