Skip to content

Commit e331ec5

Browse files
MessageDispatcher -> Caller
1 parent f7be53a commit e331ec5

File tree

5 files changed

+14
-26
lines changed

5 files changed

+14
-26
lines changed

src/message_dispatcher.rs renamed to src/caller.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use protocol::{Deserializer, ThriftDeserializer, ThriftMessage, Error};
22
use tangle::Future;
33

4-
pub trait Dispatcher<D>
4+
pub trait Caller<D>
55
where D: Deserializer + ThriftDeserializer
66
{
77
fn call(&mut self, de: &mut D, msg: ThriftMessage) -> Result<Future<Vec<u8>>, Error>;

src/dispatcher.rs

Whitespace-only changes.

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ pub mod protocol;
2424
pub mod binary_protocol;
2525
mod service;
2626
mod pipeline;
27-
mod message_dispatcher;
27+
mod caller;
28+
mod dispatcher;
2829

2930
pub type ThriftResult<T> = Result<T, ThriftCompilerError>;
3031

src/pipeline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use protocol::{Error, ThriftDeserializer, Deserializer, ThriftMessageType, ThriftMessage};
22
use tangle::{Future, Async};
3-
use message_dispatcher::Dispatcher;
3+
use caller::Caller;
44

55
pub struct MessagePipeline<D> {
66
de: D
@@ -17,7 +17,7 @@ impl<D> MessagePipeline<D>
1717

1818
/// XXX: The fn signature should be `Result<Future<Vec<u8>>, Error>` where the serialized
1919
/// response is returned into the future.
20-
pub fn run(&mut self, dispatcher: &mut Dispatcher<D>) -> Result<Future<Vec<u8>>, Error> {
20+
pub fn run(&mut self, dispatcher: &mut Caller<D>) -> Result<Future<Vec<u8>>, Error> {
2121
let msg = try!(self.de.read_message_begin());
2222

2323
match msg.ty {

src/service.rs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@ use binary_protocol::{BinarySerializer, BinaryDeserializer};
44
use std::io::Cursor;
55
use tangle::{Future, Async};
66
use pipeline::MessagePipeline;
7-
use message_dispatcher::Dispatcher;
7+
use caller::Caller;
8+
use std::sync::mpsc::{Sender, Receiver, channel};
89

910
pub trait Service {
1011
fn query(&mut self, val: bool) -> Future<()>;
1112
}
1213

13-
pub struct DispatchService<'a> {
14+
pub struct ServiceCaller<'a> {
1415
service: &'a mut Service
1516
}
1617

17-
impl<'a> DispatchService<'a> {
18-
pub fn new(service: &'a mut Service) -> DispatchService<'a> {
19-
DispatchService {
18+
impl<'a> ServiceCaller<'a> {
19+
pub fn new(service: &'a mut Service) -> ServiceCaller<'a> {
20+
ServiceCaller {
2021
service: service
2122
}
2223
}
2324
}
2425

25-
impl<'a, D> Dispatcher<D> for DispatchService<'a>
26+
impl<'a, D> Caller<D> for ServiceCaller<'a>
2627
where D: Deserializer + ThriftDeserializer
2728
{
2829
fn call(&mut self, de: &mut D, msg: ThriftMessage) -> Result<Future<Vec<u8>>, Error> {
@@ -89,10 +90,6 @@ impl Serialize for QueryArgs {
8990
}
9091
}
9192

92-
fn dispatch_query(service: &mut Service, args: QueryArgs) {
93-
service.query(args.val);
94-
}
95-
9693
pub struct RpcClient {
9794
buf: Vec<u8>
9895
}
@@ -141,18 +138,8 @@ fn call_query() {
141138

142139
let mut de = BinaryDeserializer::new(Cursor::new(buf));
143140
let mut s = Server;
144-
let mut pipe = MessagePipeline::new(de);
145-
// XXX: Expect a future as return value.
146-
//
147-
// ```notrust
148-
// pipe.run().and_then(|res| {
149-
// // ...
150-
// })
151-
// ```
152-
//
153-
// Where `res` is the serialized response.
154-
let mut dispatcher = DispatchService::new(&mut s);
155-
pipe.run(&mut dispatcher).unwrap().and_then(|v| {
141+
let mut caller = ServiceCaller::new(&mut s);
142+
MessagePipeline::new(de).run(&mut caller).unwrap().and_then(|v| {
156143
println!("{:?}", v);
157144
Async::Ok(())
158145
});

0 commit comments

Comments
 (0)