Skip to content

Commit 6b22d6f

Browse files
faerndebris
authored andcommitted
Adapt to Futures 0.1.15 by not using boxed() (#196)
* Add local BoxFuture and use it * Stop using boxed() in core * Stop using boxed() in ws * Stop using boxed() in tcp * Stop using boxed() in http * Stop using boxed() in minihttp * Stop using boxed() in macros * Stop using boxed() in ipc * Remove unused imports * Stop using boxed() in pubsub * Remove unused crates
1 parent 7f06234 commit 6b22d6f

File tree

29 files changed

+105
-108
lines changed

29 files changed

+105
-108
lines changed

core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use jsonrpc_core::futures::Future;
4949
fn main() {
5050
let io = IoHandler::new();
5151
io.add_async_method("say_hello", |_params: Params| {
52-
futures::finished(Value::String("hello".into())).boxed()
52+
Box::new(futures::finished(Value::String("hello".into())))
5353
});
5454

5555
let request = r#"{"jsonrpc": "2.0", "method": "say_hello", "params": [42, 23], "id": 1}"#;

core/examples/middlewares.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ impl Middleware<Meta> for MyMiddleware {
2222
let request_number = self.0.fetch_add(1, atomic::Ordering::SeqCst);
2323
println!("Processing request {}: {:?}, {:?}", request_number, request, meta);
2424

25-
next(request, meta).map(move |res| {
25+
Box::new(next(request, meta).map(move |res| {
2626
println!("Processing took: {:?}", start.elapsed());
2727
res
28-
}).boxed()
28+
}))
2929
}
3030
}
3131

core/src/calls.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::sync::Arc;
22
use types::{Params, Value, Error};
3-
use futures::{BoxFuture, Future};
3+
use futures::Future;
4+
use BoxFuture;
45

56
/// Metadata trait
67
pub trait Metadata: Default + Clone + Send + 'static {}
@@ -60,7 +61,7 @@ impl<F: Send + Sync + 'static, X: Send + 'static> RpcMethodSimple for F where
6061
X: Future<Item=Value, Error=Error>,
6162
{
6263
fn call(&self, params: Params) -> BoxFuture<Value, Error> {
63-
self(params).boxed()
64+
Box::new(self(params))
6465
}
6566
}
6667

@@ -78,7 +79,7 @@ impl<F: Send + Sync + 'static, X: Send + 'static, T> RpcMethod<T> for F where
7879
X: Future<Item=Value, Error=Error>,
7980
{
8081
fn call(&self, params: Params, meta: T) -> BoxFuture<Value, Error> {
81-
self(params, meta).boxed()
82+
Box::new(self(params, meta))
8283
}
8384
}
8485

core/src/io.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use std::collections::HashMap;
33
use std::ops::{Deref, DerefMut};
44

55
use serde_json;
6-
use futures::{self, future, Future, BoxFuture};
6+
use futures::{self, future, Future};
77

88
use calls::{RemoteProcedure, Metadata, RpcMethodSync, RpcMethodSimple, RpcMethod, RpcNotificationSimple, RpcNotification};
99
use middleware::{self, Middleware};
1010
use types::{Params, Error, ErrorCode, Version};
1111
use types::{Request, Response, Call, Output};
12+
use BoxFuture;
1213

1314
/// A type representing middleware or RPC response before serialization.
1415
pub type FutureResponse = BoxFuture<Option<Response>, ()>;
@@ -178,11 +179,11 @@ impl<T: Metadata, S: Middleware<T>> MetaIoHandler<T, S> {
178179
Ok(request) => B(self.handle_rpc_request(request, meta)),
179180
};
180181

181-
result.map(|response| {
182+
Box::new(result.map(|response| {
182183
let res = response.map(write_response);
183184
debug!(target: "rpc", "Response: {:?}.", res);
184185
res
185-
}).boxed()
186+
}))
186187
}
187188

188189
/// Handle deserialized RPC request.
@@ -234,9 +235,9 @@ impl<T: Metadata, S: Middleware<T>> MetaIoHandler<T, S> {
234235
};
235236

236237
match result {
237-
Ok(result) => A(result
238+
Ok(result) => A(Box::new(result
238239
.then(move |result| futures::finished(Some(Output::from(result, id, jsonrpc))))
239-
.boxed()),
240+
)),
240241
Err(err) => B(futures::finished(Some(Output::from(Err(err), id, jsonrpc)))),
241242
}
242243
},

core/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ mod io;
3636
mod middleware;
3737
pub mod types;
3838

39+
/// A `Future` trait object.
40+
pub type BoxFuture<T, E> = Box<futures::Future<Item = T, Error = E> + Send>;
41+
3942
pub use calls::{RemoteProcedure, Metadata, RpcMethodSync, RpcMethodSimple, RpcMethod, RpcNotificationSimple, RpcNotification};
4043
pub use io::{Compatibility, IoHandler, MetaIoHandler, FutureResponse};
4144
pub use middleware::{Middleware, Noop as NoopMiddleware};

core/src/middleware.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
33
use calls::Metadata;
44
use types::{Request, Response};
5-
use futures::{Future, BoxFuture};
5+
use futures::Future;
6+
use BoxFuture;
67

78
/// RPC middleware
89
pub trait Middleware<M: Metadata>: Send + Sync + 'static {
@@ -27,7 +28,7 @@ impl<M: Metadata> Middleware<M> for Noop {
2728
F: FnOnce(Request, M) -> X + Send,
2829
X: Future<Item=Option<Response>, Error=()> + Send + 'static,
2930
{
30-
process(request, meta).boxed()
31+
Box::new(process(request, meta))
3132
}
3233
}
3334

http/src/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use hyper::{self, mime, server, Method};
77
use hyper::header::{self, Headers};
88
use unicase::Ascii;
99

10-
use jsonrpc::{Metadata, Middleware, NoopMiddleware};
11-
use jsonrpc::futures::{Future, Poll, Async, BoxFuture, Stream};
10+
use jsonrpc::{BoxFuture, Metadata, Middleware, NoopMiddleware};
11+
use jsonrpc::futures::{Future, Poll, Async, Stream};
1212
use response::Response;
1313
use server_utils::cors;
1414

http/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ use std::sync::{mpsc, Arc};
3838
use std::net::SocketAddr;
3939

4040
use hyper::server;
41-
use jsonrpc::MetaIoHandler;
42-
use jsonrpc::futures::{self, Future, IntoFuture, BoxFuture, Stream};
41+
use jsonrpc::{BoxFuture, MetaIoHandler};
42+
use jsonrpc::futures::{self, Future, IntoFuture, Stream};
4343
use jsonrpc::futures::sync::oneshot;
4444
use server_utils::reactor::{Remote, UninitializedRemote};
4545

@@ -132,7 +132,7 @@ impl<T> From<Option<T>> for RequestMiddlewareAction where
132132
},
133133
Some(handler) => RequestMiddlewareAction::Respond {
134134
should_validate_hosts: true,
135-
handler: handler.into_future().boxed(),
135+
handler: Box::new(handler.into_future()),
136136
},
137137
}
138138
}

http/src/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ fn serve() -> Server {
2121
let mut io = IoHandler::default();
2222
io.add_method("hello", |_params: Params| Ok(Value::String("world".into())));
2323
io.add_async_method("hello_async", |_params: Params| {
24-
futures::finished(Value::String("world".into())).boxed()
24+
Box::new(futures::finished(Value::String("world".into())))
2525
});
2626
io.add_async_method("hello_async2", |_params: Params| {
2727
let (c, p) = futures::oneshot();
2828
thread::spawn(move || {
2929
thread::sleep(::std::time::Duration::from_millis(10));
3030
c.send(Value::String("world".into())).unwrap();
3131
});
32-
p.map_err(|_| Error::invalid_request()).boxed()
32+
Box::new(p.map_err(|_| Error::invalid_request()))
3333
});
3434

3535
ServerBuilder::new(io)

ipc/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ tokio-service = "0.1"
1414
jsonrpc-core = { version = "7.1", path = "../core" }
1515
jsonrpc-server-utils = { version = "7.1", path = "../server-utils" }
1616
parity-tokio-ipc = { git = "https://github.com/nikvolf/parity-tokio-ipc" }
17-
bytes = "0.4"
1817

1918
[dev-dependencies]
2019
env_logger = "0.4"

0 commit comments

Comments
 (0)