1919
2020#![ warn( missing_docs) ]
2121
22- #[ macro_use] extern crate log;
2322extern crate unicase;
2423extern crate jsonrpc_core as jsonrpc;
2524extern crate jsonrpc_server_utils as server_utils;
2625extern crate net2;
2726
2827pub extern crate hyper;
2928
30- mod response;
29+ #[ macro_use]
30+ extern crate log;
31+
3132mod handler;
33+ mod response;
3234mod utils;
3335#[ cfg( test) ]
3436mod tests;
3537
36- use std:: { fmt , io } ;
38+ use std:: io ;
3739use std:: sync:: { mpsc, Arc } ;
3840use std:: net:: SocketAddr ;
3941
4042use hyper:: server;
41- use jsonrpc:: { BoxFuture , MetaIoHandler } ;
43+ use jsonrpc:: MetaIoHandler ;
4244use jsonrpc:: futures:: { self , Future , Stream } ;
4345use jsonrpc:: futures:: sync:: oneshot;
4446use server_utils:: reactor:: { Remote , UninitializedRemote } ;
@@ -50,55 +52,6 @@ pub use handler::ServerHandler;
5052pub use utils:: { is_host_allowed, cors_header, CorsHeader } ;
5153pub use response:: Response ;
5254
53- /// Result of starting the Server.
54- pub type ServerResult = Result < Server , Error > ;
55-
56- /// RPC Server startup error.
57- #[ derive( Debug ) ]
58- pub enum Error {
59- /// IO Error
60- Io ( std:: io:: Error ) ,
61- /// Other Error (hyper)
62- Other ( hyper:: error:: Error ) ,
63- }
64-
65- impl From < std:: io:: Error > for Error {
66- fn from ( err : std:: io:: Error ) -> Self {
67- Error :: Io ( err)
68- }
69- }
70-
71- impl From < hyper:: error:: Error > for Error {
72- fn from ( err : hyper:: error:: Error ) -> Self {
73- match err {
74- hyper:: error:: Error :: Io ( e) => Error :: Io ( e) ,
75- e => Error :: Other ( e)
76- }
77- }
78- }
79-
80- impl fmt:: Display for Error {
81- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
82- match * self {
83- Error :: Io ( ref e) => e. fmt ( f) ,
84- Error :: Other ( ref e) => e. fmt ( f) ,
85- }
86- }
87- }
88-
89- impl :: std:: error:: Error for Error {
90- fn description ( & self ) -> & str {
91- "Starting the JSON-RPC HTTP server failed"
92- }
93-
94- fn cause ( & self ) -> Option < & :: std:: error:: Error > {
95- Some ( match * self {
96- Error :: Io ( ref e) => e,
97- Error :: Other ( ref e) => e,
98- } )
99- }
100- }
101-
10255/// Action undertaken by a middleware.
10356pub enum RequestMiddlewareAction {
10457 /// Proceed with standard RPC handling
@@ -114,7 +67,7 @@ pub enum RequestMiddlewareAction {
11467 /// Should standard hosts validation be performed?
11568 should_validate_hosts : bool ,
11669 /// a future for server response
117- response : BoxFuture < server:: Response , hyper:: Error > ,
70+ response : Box < Future < Item = server:: Response , Error = hyper:: Error > + Send > ,
11871 }
11972}
12073
@@ -338,7 +291,7 @@ impl<M: jsonrpc::Metadata, S: jsonrpc::Middleware<M>> ServerBuilder<M, S> {
338291 }
339292
340293 /// Start this JSON-RPC HTTP server trying to bind to specified `SocketAddr`.
341- pub fn start_http ( self , addr : & SocketAddr ) -> ServerResult {
294+ pub fn start_http ( self , addr : & SocketAddr ) -> io :: Result < Server > {
342295 let cors_domains = self . cors_domains ;
343296 let request_middleware = self . request_middleware ;
344297 let allowed_hosts = self . allowed_hosts ;
0 commit comments