From 37b62a37fd0d39735fac7a42933e0ebc154561f6 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Tue, 29 Jan 2019 15:34:53 +0000 Subject: [PATCH] Migrate to edition 2018 (#368) * core: cargo fix --edition * core: edition = 2018 * http: cargo fix --edition * http: edition = 2018 * ipc: edition 2018 * pubsub: edition 2018 * pubsub: cargo fix --edition-idioms --broken-code, then fixed compile errors * server-utils: cargo fix --edition * server-utils: edition 2018 * server-utils: cargo fix --edition-idioms --broken-code * stdio: edition 2018 * stdio: edition 2018 idioms * tcp: edition 2018 * tcp: edition 2018 idioms * test: edition 2018 * test: edition 2018 idioms * ws: edition 2018 * ws: edition 2018 idioms * edition 2018: remove whitespaces from cargo fix * core: edition 2018 idioms * http: edition 2018 idioms * derive: edition 2018 idioms * ipc: edition 2018 idioms * pubsub: edition 2018 idioms * Remove more blank lines and unused * Remove all `dyn` keywords for trait objects * Remove anonymous lifetimes * Replace `r#try` with `?` * Remove `extern crate` in doctests * Remove `extern crate` in READMEs * Convert doctest to use derive instead of macros --- core/Cargo.toml | 1 + core/README.md | 4 --- core/examples/async.rs | 2 -- core/examples/basic.rs | 2 -- core/examples/meta.rs | 2 -- core/examples/middlewares.rs | 2 -- core/src/calls.rs | 4 +-- core/src/delegates.rs | 6 ++--- core/src/io.rs | 10 ++++---- core/src/lib.rs | 15 +++++------ core/src/middleware.rs | 4 +-- core/src/types/error.rs | 2 +- core/src/types/params.rs | 2 +- core/src/types/response.rs | 2 +- derive/examples/generic-trait.rs | 2 +- derive/tests/compiletests.rs | 2 +- derive/tests/pubsub-macros.rs | 6 ++--- http/Cargo.toml | 1 + http/README.md | 2 -- http/examples/http_async.rs | 2 -- http/examples/http_meta.rs | 3 --- http/examples/http_middleware.rs | 2 -- http/examples/server.rs | 2 -- http/src/handler.rs | 14 +++++----- http/src/lib.rs | 37 ++++++++++++--------------- http/src/tests.rs | 2 +- http/src/utils.rs | 2 +- ipc/Cargo.toml | 1 + ipc/README.md | 2 -- ipc/examples/ipc.rs | 2 +- ipc/src/lib.rs | 13 ++++------ ipc/src/meta.rs | 6 ++--- ipc/src/select_with_weak.rs | 4 +-- ipc/src/server.rs | 44 ++++++++++++++++---------------- pubsub/Cargo.toml | 1 + pubsub/examples/pubsub.rs | 4 --- pubsub/examples/pubsub_simple.rs | 4 --- pubsub/src/delegates.rs | 10 ++++---- pubsub/src/handler.rs | 18 ++++++------- pubsub/src/lib.rs | 4 +-- pubsub/src/subscription.rs | 20 +++++++-------- pubsub/src/typed.rs | 22 ++++++++-------- pubsub/src/types.rs | 8 +++--- server-utils/Cargo.toml | 1 + server-utils/src/cors.rs | 8 +++--- server-utils/src/hosts.rs | 2 +- server-utils/src/lib.rs | 15 +++++------ server-utils/src/reactor.rs | 4 +-- stdio/Cargo.toml | 1 + stdio/README.md | 2 -- stdio/examples/stdio.rs | 2 -- stdio/src/lib.rs | 10 +++----- tcp/Cargo.toml | 1 + tcp/README.md | 2 -- tcp/examples/tcp.rs | 3 +-- tcp/src/dispatch.rs | 6 ++--- tcp/src/lib.rs | 16 ++++-------- tcp/src/meta.rs | 4 +-- tcp/src/server.rs | 14 +++++----- tcp/src/service.rs | 2 +- tcp/src/tests.rs | 26 +++++++++---------- test/Cargo.toml | 5 +++- test/src/lib.rs | 27 +++++++++----------- ws/Cargo.toml | 1 + ws/README.md | 2 -- ws/examples/ws.rs | 2 -- ws/src/error.rs | 2 +- ws/src/lib.rs | 8 +++--- ws/src/metadata.rs | 12 ++++----- ws/src/server.rs | 20 +++++++-------- ws/src/server_builder.rs | 20 +++++++-------- ws/src/session.rs | 22 ++++++++-------- ws/src/tests.rs | 16 ++++++------ 73 files changed, 246 insertions(+), 308 deletions(-) diff --git a/core/Cargo.toml b/core/Cargo.toml index 4c6afec8b..d54bd2de8 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -8,6 +8,7 @@ version = "10.0.0" authors = ["debris "] keywords = ["jsonrpc", "json-rpc", "json", "rpc", "serde"] documentation = "https://paritytech.github.io/jsonrpc/jsonrpc_core/index.html" +edition = "2018" categories = [ "asynchronous", diff --git a/core/README.md b/core/README.md index 7ec5b9d46..13f5e9f64 100644 --- a/core/README.md +++ b/core/README.md @@ -19,8 +19,6 @@ jsonrpc-core = "4.0" `main.rs` ```rust -extern crate jsonrpc_core; - use jsonrpc_core::*; fn main() { @@ -41,8 +39,6 @@ fn main() { `main.rs` ```rust -extern crate jsonrpc_core; - use jsonrpc_core::*; use jsonrpc_core::futures::Future; diff --git a/core/examples/async.rs b/core/examples/async.rs index 29d0b4f9c..5040e8bd8 100644 --- a/core/examples/async.rs +++ b/core/examples/async.rs @@ -1,5 +1,3 @@ -extern crate jsonrpc_core; - use jsonrpc_core::*; use jsonrpc_core::futures::Future; diff --git a/core/examples/basic.rs b/core/examples/basic.rs index 22300d575..8afb42b32 100644 --- a/core/examples/basic.rs +++ b/core/examples/basic.rs @@ -1,5 +1,3 @@ -extern crate jsonrpc_core; - use jsonrpc_core::*; fn main() { diff --git a/core/examples/meta.rs b/core/examples/meta.rs index e1d8db59a..2569e426f 100644 --- a/core/examples/meta.rs +++ b/core/examples/meta.rs @@ -1,5 +1,3 @@ -extern crate jsonrpc_core; - use jsonrpc_core::*; use jsonrpc_core::futures::Future; diff --git a/core/examples/middlewares.rs b/core/examples/middlewares.rs index 60a09fde4..a16c915f2 100644 --- a/core/examples/middlewares.rs +++ b/core/examples/middlewares.rs @@ -1,5 +1,3 @@ -extern crate jsonrpc_core; - use std::time::Instant; use std::sync::atomic::{self, AtomicUsize}; use jsonrpc_core::*; diff --git a/core/src/calls.rs b/core/src/calls.rs index 997f7276f..b02ad8a7d 100644 --- a/core/src/calls.rs +++ b/core/src/calls.rs @@ -1,8 +1,8 @@ use std::fmt; use std::sync::Arc; -use types::{Params, Value, Error}; +use crate::types::{Params, Value, Error}; use futures::{Future, IntoFuture}; -use BoxFuture; +use crate::BoxFuture; /// Metadata trait pub trait Metadata: Clone + Send + 'static {} diff --git a/core/src/delegates.rs b/core/src/delegates.rs index 7dd6000aa..2fa13f4af 100644 --- a/core/src/delegates.rs +++ b/core/src/delegates.rs @@ -3,10 +3,10 @@ use std::sync::Arc; use std::collections::HashMap; -use types::{Params, Value, Error}; -use calls::{Metadata, RemoteProcedure, RpcMethod, RpcNotification}; +use crate::types::{Params, Value, Error}; +use crate::calls::{Metadata, RemoteProcedure, RpcMethod, RpcNotification}; use futures::IntoFuture; -use BoxFuture; +use crate::BoxFuture; struct DelegateAsyncMethod { delegate: Arc, diff --git a/core/src/io.rs b/core/src/io.rs index 43d8cc4da..cc163d631 100644 --- a/core/src/io.rs +++ b/core/src/io.rs @@ -5,10 +5,10 @@ use std::ops::{Deref, DerefMut}; use serde_json; use futures::{self, future, Future}; -use calls::{RemoteProcedure, Metadata, RpcMethodSimple, RpcMethod, RpcNotificationSimple, RpcNotification}; -use middleware::{self, Middleware}; -use types::{Error, ErrorCode, Version}; -use types::{Request, Response, Call, Output}; +use crate::calls::{RemoteProcedure, Metadata, RpcMethodSimple, RpcMethod, RpcNotificationSimple, RpcNotification}; +use crate::middleware::{self, Middleware}; +use crate::types::{Error, ErrorCode, Version}; +use crate::types::{Request, Response, Call, Output}; /// A type representing middleware or RPC response before serialization. pub type FutureResponse = Box, Error=()> + Send>; @@ -372,7 +372,7 @@ fn write_response(response: Response) -> String { #[cfg(test)] mod tests { use futures; - use types::{Value}; + use crate::types::{Value}; use super::{IoHandler, Compatibility}; #[test] diff --git a/core/src/lib.rs b/core/src/lib.rs index 6da2334af..0bdeb2e92 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -3,8 +3,6 @@ //! Right now it supports only server side handling requests. //! //! ```rust -//! extern crate jsonrpc_core; -//! //! use jsonrpc_core::*; //! use jsonrpc_core::futures::Future; //! @@ -25,9 +23,8 @@ #[macro_use] extern crate log; #[macro_use] extern crate serde_derive; -extern crate serde; -pub extern crate futures; +pub use futures; #[doc(hidden)] pub extern crate serde_json; @@ -45,8 +42,8 @@ pub type BoxFuture = Box + Send>; /// A Result type. pub type Result = ::std::result::Result; -pub use calls::{RemoteProcedure, Metadata, RpcMethodSimple, RpcMethod, RpcNotificationSimple, RpcNotification}; -pub use delegates::IoDelegate; -pub use io::{Compatibility, IoHandler, MetaIoHandler, FutureOutput, FutureResult, FutureResponse, FutureRpcResult}; -pub use middleware::{Middleware, Noop as NoopMiddleware}; -pub use types::*; +pub use crate::calls::{RemoteProcedure, Metadata, RpcMethodSimple, RpcMethod, RpcNotificationSimple, RpcNotification}; +pub use crate::delegates::IoDelegate; +pub use crate::io::{Compatibility, IoHandler, MetaIoHandler, FutureOutput, FutureResult, FutureResponse, FutureRpcResult}; +pub use crate::middleware::{Middleware, Noop as NoopMiddleware}; +pub use crate::types::*; diff --git a/core/src/middleware.rs b/core/src/middleware.rs index 699e2853e..1300d219e 100644 --- a/core/src/middleware.rs +++ b/core/src/middleware.rs @@ -1,7 +1,7 @@ //! `IoHandler` middlewares -use calls::Metadata; -use types::{Request, Response, Call, Output}; +use crate::calls::Metadata; +use crate::types::{Request, Response, Call, Output}; use futures::{future::Either, Future}; /// RPC middleware diff --git a/core/src/types/error.rs b/core/src/types/error.rs index 6f7a573af..d3a7e088c 100644 --- a/core/src/types/error.rs +++ b/core/src/types/error.rs @@ -65,7 +65,7 @@ impl From for ErrorCode { impl<'a> Deserialize<'a> for ErrorCode { fn deserialize(deserializer: D) -> Result where D: Deserializer<'a> { - let code: i64 = try!(Deserialize::deserialize(deserializer)); + let code: i64 = Deserialize::deserialize(deserializer)?; Ok(ErrorCode::from(code)) } } diff --git a/core/src/types/params.rs b/core/src/types/params.rs index 60cfed9ae..27bf4b4af 100644 --- a/core/src/types/params.rs +++ b/core/src/types/params.rs @@ -46,7 +46,7 @@ impl Params { mod tests { use serde_json; use super::Params; - use types::{Value, Error, ErrorCode}; + use crate::types::{Value, Error, ErrorCode}; #[test] fn params_deserialization() { diff --git a/core/src/types/response.rs b/core/src/types/response.rs index 7b562bd36..95e13520d 100644 --- a/core/src/types/response.rs +++ b/core/src/types/response.rs @@ -1,6 +1,6 @@ //! jsonrpc response use super::{Id, Value, Error, ErrorCode, Version}; -use {Result as CoreResult}; +use crate::{Result as CoreResult}; /// Successful response #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] diff --git a/derive/examples/generic-trait.rs b/derive/examples/generic-trait.rs index 94db24452..89504d56f 100644 --- a/derive/examples/generic-trait.rs +++ b/derive/examples/generic-trait.rs @@ -1,4 +1,4 @@ -extern crate jsonrpc_core; +use jsonrpc_core; use jsonrpc_core::{IoHandler, Error, Result}; use jsonrpc_core::futures::future::{self, FutureResult}; diff --git a/derive/tests/compiletests.rs b/derive/tests/compiletests.rs index dd9d90795..60d493da1 100644 --- a/derive/tests/compiletests.rs +++ b/derive/tests/compiletests.rs @@ -1,4 +1,4 @@ -extern crate compiletest_rs as compiletest; +use compiletest_rs as compiletest; use std::path::PathBuf; diff --git a/derive/tests/pubsub-macros.rs b/derive/tests/pubsub-macros.rs index 6bb2eacf9..c7f8a82b5 100644 --- a/derive/tests/pubsub-macros.rs +++ b/derive/tests/pubsub-macros.rs @@ -1,6 +1,6 @@ -extern crate serde_json; -extern crate jsonrpc_core; -extern crate jsonrpc_pubsub; +use serde_json; +use jsonrpc_core; +use jsonrpc_pubsub; #[macro_use] extern crate jsonrpc_derive; diff --git a/http/Cargo.toml b/http/Cargo.toml index d5954b647..b3e6aa5d5 100644 --- a/http/Cargo.toml +++ b/http/Cargo.toml @@ -8,6 +8,7 @@ version = "10.0.0" authors = ["debris "] keywords = ["jsonrpc", "json-rpc", "json", "rpc", "server"] documentation = "https://paritytech.github.io/jsonrpc/jsonrpc_http_server/index.html" +edition = "2018" [dependencies] hyper = "0.12" diff --git a/http/README.md b/http/README.md index d2da0d720..dd4e84ff7 100644 --- a/http/README.md +++ b/http/README.md @@ -15,8 +15,6 @@ jsonrpc-http-server = "10.0" `main.rs` ```rust -extern crate jsonrpc_http_server; - use jsonrpc_http_server::*; use jsonrpc_http_server::jsonrpc_core::*; diff --git a/http/examples/http_async.rs b/http/examples/http_async.rs index e2bed681a..f0da3cd32 100644 --- a/http/examples/http_async.rs +++ b/http/examples/http_async.rs @@ -1,5 +1,3 @@ -extern crate jsonrpc_http_server; - use jsonrpc_http_server::{ServerBuilder, DomainsValidation, AccessControlAllowOrigin}; use jsonrpc_http_server::jsonrpc_core::*; diff --git a/http/examples/http_meta.rs b/http/examples/http_meta.rs index 5338f1da0..a87df82bb 100644 --- a/http/examples/http_meta.rs +++ b/http/examples/http_meta.rs @@ -1,6 +1,3 @@ -extern crate jsonrpc_http_server; -extern crate unicase; - use jsonrpc_http_server::{ServerBuilder, hyper, RestApi, cors::AccessControlAllowHeaders}; use jsonrpc_http_server::jsonrpc_core::*; diff --git a/http/examples/http_middleware.rs b/http/examples/http_middleware.rs index 6caea36a7..d2ca5bee1 100644 --- a/http/examples/http_middleware.rs +++ b/http/examples/http_middleware.rs @@ -1,5 +1,3 @@ -extern crate jsonrpc_http_server; - use jsonrpc_http_server::{ hyper, ServerBuilder, DomainsValidation, AccessControlAllowOrigin, Response, RestApi }; diff --git a/http/examples/server.rs b/http/examples/server.rs index 11c7407b9..011d99abc 100644 --- a/http/examples/server.rs +++ b/http/examples/server.rs @@ -1,5 +1,3 @@ -extern crate jsonrpc_http_server; - use jsonrpc_http_server::{ServerBuilder, DomainsValidation, AccessControlAllowOrigin, RestApi}; use jsonrpc_http_server::jsonrpc_core::*; diff --git a/http/src/handler.rs b/http/src/handler.rs index c29829767..5972b6dc2 100644 --- a/http/src/handler.rs +++ b/http/src/handler.rs @@ -1,4 +1,4 @@ -use Rpc; +use crate::Rpc; use std::{fmt, mem, str}; use std::sync::Arc; @@ -6,13 +6,13 @@ use std::sync::Arc; use hyper::{self, service::Service, Body, Method}; use hyper::header::{self, HeaderMap, HeaderValue}; -use jsonrpc::{self as core, middleware, FutureResult, Metadata, Middleware}; -use jsonrpc::futures::{Future, Poll, Async, Stream, future}; -use jsonrpc::serde_json; -use response::Response; -use server_utils::cors; +use crate::jsonrpc::{self as core, middleware, FutureResult, Metadata, Middleware}; +use crate::jsonrpc::futures::{Future, Poll, Async, Stream, future}; +use crate::jsonrpc::serde_json; +use crate::response::Response; +use crate::server_utils::cors; -use {utils, RequestMiddleware, RequestMiddlewareAction, CorsDomains, AllowedHosts, RestApi}; +use crate::{utils, RequestMiddleware, RequestMiddlewareAction, CorsDomains, AllowedHosts, RestApi}; /// jsonrpc http request handler. pub struct ServerHandler = middleware::Noop> { diff --git a/http/src/lib.rs b/http/src/lib.rs index 4d89f46f8..4cdf20644 100644 --- a/http/src/lib.rs +++ b/http/src/lib.rs @@ -1,9 +1,6 @@ //! jsonrpc http server. //! //! ```no_run -//! extern crate jsonrpc_core; -//! extern crate jsonrpc_http_server; -//! //! use jsonrpc_core::*; //! use jsonrpc_http_server::*; //! @@ -23,12 +20,12 @@ #![warn(missing_docs)] -extern crate unicase; -extern crate jsonrpc_server_utils as server_utils; -extern crate net2; -pub extern crate jsonrpc_core; -pub extern crate hyper; +use jsonrpc_server_utils as server_utils; +use net2; + +pub use jsonrpc_core; +pub use hyper; #[macro_use] extern crate log; @@ -46,17 +43,17 @@ use std::thread; use hyper::{server, Body}; use jsonrpc_core as jsonrpc; -use jsonrpc::MetaIoHandler; -use jsonrpc::futures::{self, Future, Stream, future}; -use jsonrpc::futures::sync::oneshot; -use server_utils::reactor::{Executor, UninitializedExecutor}; - -pub use server_utils::hosts::{Host, DomainsValidation}; -pub use server_utils::cors::{self, AccessControlAllowOrigin, Origin, AllowCors}; -pub use server_utils::{tokio, SuspendableStream}; -pub use handler::ServerHandler; -pub use utils::{is_host_allowed, cors_allow_origin, cors_allow_headers}; -pub use response::Response; +use crate::jsonrpc::MetaIoHandler; +use crate::jsonrpc::futures::{self, Future, Stream, future}; +use crate::jsonrpc::futures::sync::oneshot; +use crate::server_utils::reactor::{Executor, UninitializedExecutor}; + +pub use crate::server_utils::hosts::{Host, DomainsValidation}; +pub use crate::server_utils::cors::{self, AccessControlAllowOrigin, Origin, AllowCors}; +pub use crate::server_utils::{tokio, SuspendableStream}; +pub use crate::handler::ServerHandler; +pub use crate::utils::{is_host_allowed, cors_allow_origin, cors_allow_headers}; +pub use crate::response::Response; /// Action undertaken by a middleware. pub enum RequestMiddlewareAction { @@ -540,7 +537,7 @@ fn configure_port(reuse: bool, tcp: &net2::TcpBuilder) -> io::Result<()> { use net2::unix::*; if reuse { - try!(tcp.reuse_port(true)); + tcp.reuse_port(true)?; } Ok(()) diff --git a/http/src/tests.rs b/http/src/tests.rs index 819c37f28..72b7eb263 100644 --- a/http/src/tests.rs +++ b/http/src/tests.rs @@ -1,4 +1,4 @@ -extern crate jsonrpc_core; +use jsonrpc_core; use std::str::Lines; use std::net::TcpStream; diff --git a/http/src/utils.rs b/http/src/utils.rs index 0640a4076..aaa417d6a 100644 --- a/http/src/utils.rs +++ b/http/src/utils.rs @@ -1,6 +1,6 @@ use hyper::{self, header}; -use server_utils::{cors, hosts}; +use crate::server_utils::{cors, hosts}; /// Extracts string value of a single header in request. fn read_header<'a>(req: &'a hyper::Request, header_name: &str) -> Option<&'a str> { diff --git a/ipc/Cargo.toml b/ipc/Cargo.toml index e0e78d52a..fe28e1cf6 100644 --- a/ipc/Cargo.toml +++ b/ipc/Cargo.toml @@ -7,6 +7,7 @@ license = "MIT" homepage = "https://github.com/paritytech/jsonrpc" repository = "https://github.com/paritytech/jsonrpc" documentation = "https://paritytech.github.io/jsonrpc/json_ipc_server/index.html" +edition = "2018" [dependencies] log = "0.4" diff --git a/ipc/README.md b/ipc/README.md index 7effc341c..b003fd74d 100644 --- a/ipc/README.md +++ b/ipc/README.md @@ -15,8 +15,6 @@ jsonrpc-ipc-server = "10.0" `main.rs` ```rust -extern crate jsonrpc_ipc_server; - use jsonrpc_ipc_server::Server; use jsonrpc_ipc_server::jsonrpc_core::*; diff --git a/ipc/examples/ipc.rs b/ipc/examples/ipc.rs index 89a45c0ce..8fb375b79 100644 --- a/ipc/examples/ipc.rs +++ b/ipc/examples/ipc.rs @@ -1,4 +1,4 @@ -extern crate jsonrpc_ipc_server; +use jsonrpc_ipc_server; use jsonrpc_ipc_server::jsonrpc_core::*; diff --git a/ipc/src/lib.rs b/ipc/src/lib.rs index deff37bf2..f7975ba2e 100644 --- a/ipc/src/lib.rs +++ b/ipc/src/lib.rs @@ -2,17 +2,14 @@ #![warn(missing_docs)] -extern crate jsonrpc_server_utils as server_utils; -extern crate parity_tokio_ipc; -extern crate tokio_service; -extern crate parking_lot; +use jsonrpc_server_utils as server_utils; -pub extern crate jsonrpc_core; +pub use jsonrpc_core; #[macro_use] extern crate log; #[cfg(test)] #[macro_use] extern crate lazy_static; -#[cfg(test)] extern crate env_logger; + #[cfg(test)] mod logger; mod server; @@ -21,8 +18,8 @@ mod meta; use jsonrpc_core as jsonrpc; -pub use meta::{MetaExtractor, NoopExtractor, RequestContext}; -pub use server::{Server, ServerBuilder, CloseHandle,SecurityAttributes}; +pub use crate::meta::{MetaExtractor, NoopExtractor, RequestContext}; +pub use crate::server::{Server, ServerBuilder, CloseHandle,SecurityAttributes}; pub use self::server_utils::{tokio, codecs::Separator}; pub use self::server_utils::session::{SessionStats, SessionId}; diff --git a/ipc/src/meta.rs b/ipc/src/meta.rs index 60e173f4a..ed3ac6ae1 100644 --- a/ipc/src/meta.rs +++ b/ipc/src/meta.rs @@ -1,6 +1,6 @@ -use jsonrpc::futures::sync::mpsc; -use jsonrpc::Metadata; -use server_utils::session; +use crate::jsonrpc::futures::sync::mpsc; +use crate::jsonrpc::Metadata; +use crate::server_utils::session; /// Request context pub struct RequestContext<'a> { diff --git a/ipc/src/select_with_weak.rs b/ipc/src/select_with_weak.rs index 204059c27..bc96bff45 100644 --- a/ipc/src/select_with_weak.rs +++ b/ipc/src/select_with_weak.rs @@ -1,5 +1,5 @@ -use jsonrpc::futures::{Poll, Async}; -use jsonrpc::futures::stream::{Stream, Fuse}; +use crate::jsonrpc::futures::{Poll, Async}; +use crate::jsonrpc::futures::stream::{Stream, Fuse}; pub trait SelectWithWeakExt: Stream { fn select_with_weak(self, other: S) -> SelectWithWeak diff --git a/ipc/src/server.rs b/ipc/src/server.rs index 568805249..69443886d 100644 --- a/ipc/src/server.rs +++ b/ipc/src/server.rs @@ -4,19 +4,19 @@ use std; use std::sync::Arc; use tokio_service::{self, Service as TokioService}; -use jsonrpc::futures::{future, Future, Stream, Sink}; -use jsonrpc::futures::sync::{mpsc, oneshot}; -use jsonrpc::{middleware, FutureResult, Metadata, MetaIoHandler, Middleware}; +use crate::jsonrpc::futures::{future, Future, Stream, Sink}; +use crate::jsonrpc::futures::sync::{mpsc, oneshot}; +use crate::jsonrpc::{middleware, FutureResult, Metadata, MetaIoHandler, Middleware}; -use server_utils::{ +use crate::server_utils::{ tokio_codec::Framed, tokio::{self, runtime::TaskExecutor, reactor::Handle}, reactor, session, codecs, }; use parking_lot::Mutex; -use meta::{MetaExtractor, NoopExtractor, RequestContext}; -use select_with_weak::SelectWithWeakExt; +use crate::meta::{MetaExtractor, NoopExtractor, RequestContext}; +use crate::select_with_weak::SelectWithWeakExt; use parity_tokio_ipc::Endpoint; pub use parity_tokio_ipc::SecurityAttributes; @@ -309,24 +309,24 @@ impl CloseHandle { #[cfg(test)] #[cfg(not(windows))] mod tests { - extern crate tokio_uds; + use tokio_uds; use std::thread; use std::sync::Arc; use std::time; use std::time::{Instant, Duration}; use super::{ServerBuilder, Server}; - use jsonrpc::{MetaIoHandler, Value}; - use jsonrpc::futures::{Future, future, Stream, Sink}; - use jsonrpc::futures::sync::{mpsc, oneshot}; + use crate::jsonrpc::{MetaIoHandler, Value}; + use crate::jsonrpc::futures::{Future, future, Stream, Sink}; + use crate::jsonrpc::futures::sync::{mpsc, oneshot}; use self::tokio_uds::UnixStream; use parking_lot::Mutex; - use server_utils::{ + use crate::server_utils::{ tokio_codec::Decoder, tokio::{self, timer::Delay} }; - use server_utils::codecs; - use meta::{MetaExtractor, RequestContext, NoopExtractor}; + use crate::server_utils::codecs; + use crate::meta::{MetaExtractor, RequestContext, NoopExtractor}; use super::SecurityAttributes; fn server_builder() -> ServerBuilder { @@ -364,7 +364,7 @@ mod tests { #[test] fn start() { - ::logger::init_log(); + crate::logger::init_log(); let mut io = MetaIoHandler::<()>::default(); io.add_method("say_hello", |_params| { @@ -378,7 +378,7 @@ mod tests { #[test] fn connect() { - ::logger::init_log(); + crate::logger::init_log(); let path = "/tmp/test-ipc-30000"; let _server = run(path); @@ -387,7 +387,7 @@ mod tests { #[test] fn request() { - ::logger::init_log(); + crate::logger::init_log(); let path = "/tmp/test-ipc-40000"; let server = run(path); let (stop_signal, stop_receiver) = oneshot::channel(); @@ -413,7 +413,7 @@ mod tests { #[test] fn req_parallel() { - ::logger::init_log(); + crate::logger::init_log(); let path = "/tmp/test-ipc-45000"; let server = run(path); let (stop_signal, stop_receiver) = mpsc::channel(400); @@ -451,7 +451,7 @@ mod tests { #[test] fn close() { - ::logger::init_log(); + crate::logger::init_log(); let path = "/tmp/test-ipc-50000"; let server = run(path); server.close(); @@ -478,7 +478,7 @@ mod tests { #[test] fn test_huge_response() { - ::logger::init_log(); + crate::logger::init_log(); let path = "/tmp/test-ipc-60000"; let mut io = MetaIoHandler::<()>::default(); @@ -538,7 +538,7 @@ mod tests { } } - ::logger::init_log(); + crate::logger::init_log(); let path = "/tmp/test-ipc-30009"; let (signal, receiver) = mpsc::channel(16); let session_metadata_extractor = SessionEndExtractor { @@ -561,7 +561,7 @@ mod tests { #[test] fn close_handle() { - ::logger::init_log(); + crate::logger::init_log(); let path = "/tmp/test-ipc-90000"; let server = run(path); let handle = server.close_handle(); @@ -571,7 +571,7 @@ mod tests { #[test] fn close_when_waiting() { - ::logger::init_log(); + crate::logger::init_log(); let path = "/tmp/test-ipc-70000"; let server = run(path); let close_handle = server.close_handle(); diff --git a/pubsub/Cargo.toml b/pubsub/Cargo.toml index c0fd70972..4881ec492 100644 --- a/pubsub/Cargo.toml +++ b/pubsub/Cargo.toml @@ -8,6 +8,7 @@ version = "10.0.0" authors = ["tomusdrw "] keywords = ["jsonrpc", "json-rpc", "json", "rpc", "macros"] documentation = "https://paritytech.github.io/jsonrpc/jsonrpc_pubsub/index.html" +edition = "2018" [dependencies] log = "0.4" diff --git a/pubsub/examples/pubsub.rs b/pubsub/examples/pubsub.rs index a598003ff..99d4335f1 100644 --- a/pubsub/examples/pubsub.rs +++ b/pubsub/examples/pubsub.rs @@ -1,7 +1,3 @@ -extern crate jsonrpc_core; -extern crate jsonrpc_pubsub; -extern crate jsonrpc_tcp_server; - use std::{time, thread}; use std::sync::{Arc, atomic}; diff --git a/pubsub/examples/pubsub_simple.rs b/pubsub/examples/pubsub_simple.rs index db31d02d4..933d857ba 100644 --- a/pubsub/examples/pubsub_simple.rs +++ b/pubsub/examples/pubsub_simple.rs @@ -1,7 +1,3 @@ -extern crate jsonrpc_core; -extern crate jsonrpc_pubsub; -extern crate jsonrpc_tcp_server; - use std::{time, thread}; use std::sync::Arc; diff --git a/pubsub/src/delegates.rs b/pubsub/src/delegates.rs index 6fcc0eb73..988cc6e86 100644 --- a/pubsub/src/delegates.rs +++ b/pubsub/src/delegates.rs @@ -2,11 +2,11 @@ use std::marker::PhantomData; use std::sync::Arc; use std::collections::HashMap; -use subscription::{Subscriber, new_subscription}; -use handler::{SubscribeRpcMethod, UnsubscribeRpcMethod}; -use types::{SubscriptionId, PubSubMetadata}; -use core::{self, Params, Value, Error, Metadata, RemoteProcedure, RpcMethod}; -use core::futures::IntoFuture; +use crate::subscription::{Subscriber, new_subscription}; +use crate::handler::{SubscribeRpcMethod, UnsubscribeRpcMethod}; +use crate::types::{SubscriptionId, PubSubMetadata}; +use crate::core::{self, Params, Value, Error, Metadata, RemoteProcedure, RpcMethod}; +use crate::core::futures::IntoFuture; struct DelegateSubscription { delegate: Arc, diff --git a/pubsub/src/handler.rs b/pubsub/src/handler.rs index bf8675de1..a2ca608cc 100644 --- a/pubsub/src/handler.rs +++ b/pubsub/src/handler.rs @@ -1,8 +1,8 @@ -use core; -use core::futures::{Future, IntoFuture}; +use crate::core; +use crate::core::futures::{Future, IntoFuture}; -use types::{PubSubMetadata, SubscriptionId}; -use subscription::{Subscriber, new_subscription}; +use crate::types::{PubSubMetadata, SubscriptionId}; +use crate::subscription::{Subscriber, new_subscription}; /// Subscribe handler pub trait SubscribeRpcMethod: Send + Sync + 'static { @@ -102,11 +102,11 @@ mod tests { use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; - use core; - use core::futures::future; - use core::futures::sync::mpsc; - use subscription::{Session, Subscriber}; - use types::{PubSubMetadata, SubscriptionId}; + use crate::core; + use crate::core::futures::future; + use crate::core::futures::sync::mpsc; + use crate::subscription::{Session, Subscriber}; + use crate::types::{PubSubMetadata, SubscriptionId}; use super::PubSubHandler; diff --git a/pubsub/src/lib.rs b/pubsub/src/lib.rs index 248134439..7949549e0 100644 --- a/pubsub/src/lib.rs +++ b/pubsub/src/lib.rs @@ -2,9 +2,7 @@ #![warn(missing_docs)] -extern crate jsonrpc_core as core; -extern crate parking_lot; -extern crate serde; +use jsonrpc_core as core; #[macro_use] extern crate log; diff --git a/pubsub/src/subscription.rs b/pubsub/src/subscription.rs index d054ef72f..97ba7a8de 100644 --- a/pubsub/src/subscription.rs +++ b/pubsub/src/subscription.rs @@ -5,12 +5,12 @@ use std::collections::HashMap; use std::sync::Arc; use parking_lot::Mutex; -use core::{self, BoxFuture}; -use core::futures::{self, future, Sink as FuturesSink, Future}; -use core::futures::sync::{mpsc, oneshot}; +use crate::core::{self, BoxFuture}; +use crate::core::futures::{self, future, Sink as FuturesSink, Future}; +use crate::core::futures::sync::{mpsc, oneshot}; -use handler::{SubscribeRpcMethod, UnsubscribeRpcMethod}; -use types::{PubSubMetadata, SubscriptionId, TransportSender, TransportError, SinkResult}; +use crate::handler::{SubscribeRpcMethod, UnsubscribeRpcMethod}; +use crate::types::{PubSubMetadata, SubscriptionId, TransportSender, TransportError, SinkResult}; /// RPC client session /// Keeps track of active subscriptions and unsubscribes from them upon dropping. @@ -300,11 +300,11 @@ impl core::RpcMethod for Unsubscribe where mod tests { use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; - use core; - use core::RpcMethod; - use core::futures::{Async, Future, Stream}; - use core::futures::sync::{mpsc, oneshot}; - use types::{SubscriptionId, PubSubMetadata}; + use crate::core; + use crate::core::RpcMethod; + use crate::core::futures::{Async, Future, Stream}; + use crate::core::futures::sync::{mpsc, oneshot}; + use crate::types::{SubscriptionId, PubSubMetadata}; use super::{Session, Sink, Subscriber, new_subscription}; diff --git a/pubsub/src/typed.rs b/pubsub/src/typed.rs index 6b94da52b..99b9b9151 100644 --- a/pubsub/src/typed.rs +++ b/pubsub/src/typed.rs @@ -3,15 +3,15 @@ use std::marker::PhantomData; use serde; -use subscription; -use types::{SubscriptionId, TransportError, SinkResult}; +use crate::subscription; +use crate::types::{SubscriptionId, TransportError, SinkResult}; -use core::Value; -use core::futures::{self, Sink as FuturesSink, sync}; +use crate::core::{self, Value, Params, Error}; +use crate::core::futures::{self, Sink as FuturesSink, sync}; /// New PUB-SUB subscriber. #[derive(Debug)] -pub struct Subscriber { +pub struct Subscriber { subscriber: subscription::Subscriber, _data: PhantomData<(T, E)>, } @@ -28,7 +28,7 @@ impl Subscriber { /// Create new subscriber for tests. pub fn new_test>(method: M) -> ( Self, - sync::oneshot::Receiver>, + sync::oneshot::Receiver>, sync::mpsc::Receiver, ) { let (subscriber, id, subscription) = subscription::Subscriber::new_test(method); @@ -36,7 +36,7 @@ impl Subscriber { } /// Reject subscription with given error. - pub fn reject(self, error: core::Error) -> Result<(), ()> { + pub fn reject(self, error: Error) -> Result<(), ()> { self.subscriber.reject(error) } @@ -56,10 +56,10 @@ impl Subscriber { /// Subscriber sink. #[derive(Debug, Clone)] -pub struct Sink { +pub struct Sink { sink: subscription::Sink, id: SubscriptionId, - buffered: Option, + buffered: Option, _data: PhantomData<(T, E)>, } @@ -73,12 +73,12 @@ impl Sink { core::to_value(value).expect("Expected always-serializable type.") } - fn val_to_params(&self, val: Result) -> core::Params { + fn val_to_params(&self, val: Result) -> Params { let id = self.id.clone().into(); let val = val.map(Self::to_value).map_err(Self::to_value); - core::Params::Map(vec![ + Params::Map(vec![ ("subscription".to_owned(), id), match val { Ok(val) => ("result".to_owned(), val), diff --git a/pubsub/src/types.rs b/pubsub/src/types.rs index 31e4a7cd8..5b8aa98c1 100644 --- a/pubsub/src/types.rs +++ b/pubsub/src/types.rs @@ -1,8 +1,8 @@ use std::sync::Arc; -use core; -use core::futures::sync::mpsc; +use crate::core; +use crate::core::futures::sync::mpsc; -use subscription::Session; +use crate::subscription::Session; /// Raw transport sink for specific client. pub type TransportSender = mpsc::Sender; @@ -78,7 +78,7 @@ impl From for core::Value { #[cfg(test)] mod tests { - use core::Value; + use crate::core::Value; use super::SubscriptionId; #[test] diff --git a/server-utils/Cargo.toml b/server-utils/Cargo.toml index caad69dc5..986b69c2a 100644 --- a/server-utils/Cargo.toml +++ b/server-utils/Cargo.toml @@ -8,6 +8,7 @@ keywords = ["jsonrpc", "json-rpc", "json", "rpc", "serde"] documentation = "https://paritytech.github.io/jsonrpc/jsonrpc_core/index.html" homepage = "https://github.com/paritytech/jsonrpc" repository = "https://github.com/paritytech/jsonrpc" +edition = "2018" [dependencies] bytes = "0.4" diff --git a/server-utils/src/cors.rs b/server-utils/src/cors.rs index 78b8157d6..a0e080206 100644 --- a/server-utils/src/cors.rs +++ b/server-utils/src/cors.rs @@ -1,9 +1,9 @@ //! CORS handling utility functions -extern crate unicase; +use unicase; use std::{fmt, ops}; -use hosts::{Host, Port}; -use matcher::{Matcher, Pattern}; +use crate::hosts::{Host, Port}; +use crate::matcher::{Matcher, Pattern}; use std::collections::HashSet; pub use self::unicase::Ascii; @@ -303,7 +303,7 @@ mod tests { use std::iter; use super::*; - use hosts::Host; + use crate::hosts::Host; #[test] fn should_parse_origin() { diff --git a/server-utils/src/hosts.rs b/server-utils/src/hosts.rs index 50196fccc..457a4a4c0 100644 --- a/server-utils/src/hosts.rs +++ b/server-utils/src/hosts.rs @@ -2,7 +2,7 @@ use std::collections::HashSet; use std::net::SocketAddr; -use matcher::{Matcher, Pattern}; +use crate::matcher::{Matcher, Pattern}; const SPLIT_PROOF: &'static str = "split always returns non-empty iterator."; diff --git a/server-utils/src/lib.rs b/server-utils/src/lib.rs index b4e64ce65..ee6810999 100644 --- a/server-utils/src/lib.rs +++ b/server-utils/src/lib.rs @@ -8,13 +8,10 @@ extern crate log; #[macro_use] extern crate lazy_static; -extern crate globset; -extern crate jsonrpc_core as core; -extern crate bytes; -extern crate num_cpus; +use jsonrpc_core as core; -pub extern crate tokio; -pub extern crate tokio_codec; +pub use tokio; +pub use tokio_codec; pub mod cors; pub mod hosts; @@ -24,11 +21,11 @@ mod matcher; mod stream_codec; mod suspendable_stream; -pub use suspendable_stream::SuspendableStream; -pub use matcher::Pattern; +pub use crate::suspendable_stream::SuspendableStream; +pub use crate::matcher::Pattern; /// Codecs utilities pub mod codecs { - pub use stream_codec::{StreamCodec, Separator}; + pub use crate::stream_codec::{StreamCodec, Separator}; } diff --git a/server-utils/src/reactor.rs b/server-utils/src/reactor.rs index 38352783a..d1eb6d8ba 100644 --- a/server-utils/src/reactor.rs +++ b/server-utils/src/reactor.rs @@ -6,7 +6,7 @@ use std::sync::mpsc; use tokio; use num_cpus; -use core::futures::{self, Future}; +use crate::core::futures::{self, Future}; /// Possibly uninitialized event loop executor. #[derive(Debug)] @@ -109,7 +109,7 @@ impl RpcEventLoop { let handle = tb.spawn(move || { let core_threads = match num_cpus::get_physical() { 1 => 1, - 2...4 => 2, + 2..=4 => 2, _ => 3, }; diff --git a/stdio/Cargo.toml b/stdio/Cargo.toml index 4403b3408..a2e1c6b22 100644 --- a/stdio/Cargo.toml +++ b/stdio/Cargo.toml @@ -7,6 +7,7 @@ license = "MIT" homepage = "https://github.com/paritytech/jsonrpc" repository = "https://github.com/paritytech/jsonrpc" documentation = "https://paritytech.github.io/jsonrpc/jsonrpc_stdio_server/index.html" +edition = "2018" [dependencies] futures = "0.1.23" diff --git a/stdio/README.md b/stdio/README.md index 15c4054a2..1df9601f6 100644 --- a/stdio/README.md +++ b/stdio/README.md @@ -16,8 +16,6 @@ jsonrpc-stdio-server = "10.0" `main.rs` ```rust -extern crate jsonrpc_stdio_server; - use jsonrpc_stdio_server::server; use jsonrpc_stdio_server::jsonrpc_core::*; diff --git a/stdio/examples/stdio.rs b/stdio/examples/stdio.rs index 1a907c9d0..cf1ad56ee 100644 --- a/stdio/examples/stdio.rs +++ b/stdio/examples/stdio.rs @@ -1,5 +1,3 @@ -extern crate jsonrpc_stdio_server; - use jsonrpc_stdio_server::ServerBuilder; use jsonrpc_stdio_server::jsonrpc_core::*; diff --git a/stdio/src/lib.rs b/stdio/src/lib.rs index cfeb90f3f..1fd6d9ee8 100644 --- a/stdio/src/lib.rs +++ b/stdio/src/lib.rs @@ -1,7 +1,6 @@ //! jsonrpc server using stdin/stdout //! //! ```no_run -//! extern crate jsonrpc_stdio_server; //! //! use jsonrpc_stdio_server::ServerBuilder; //! use jsonrpc_stdio_server::jsonrpc_core::*; @@ -18,14 +17,11 @@ #![warn(missing_docs)] -extern crate futures; -extern crate tokio; -extern crate tokio_codec; -extern crate tokio_io; -extern crate tokio_stdin_stdout; +use tokio; +use tokio_stdin_stdout; #[macro_use] extern crate log; -pub extern crate jsonrpc_core; +pub use jsonrpc_core; use std::sync::Arc; use tokio::prelude::{Future, Stream}; diff --git a/tcp/Cargo.toml b/tcp/Cargo.toml index e4e2d5460..b7edae8cf 100644 --- a/tcp/Cargo.toml +++ b/tcp/Cargo.toml @@ -7,6 +7,7 @@ license = "MIT" homepage = "https://github.com/paritytech/jsonrpc" repository = "https://github.com/paritytech/jsonrpc" documentation = "https://paritytech.github.io/jsonrpc/jsonrpc_tcp_server/index.html" +edition = "2018" [dependencies] log = "0.4" diff --git a/tcp/README.md b/tcp/README.md index 83edada87..c912220a9 100644 --- a/tcp/README.md +++ b/tcp/README.md @@ -15,8 +15,6 @@ jsonrpc-tcp-server = "10.0" `main.rs` ```rust -extern crate jsonrpc_tcp_server; - use jsonrpc_tcp_server::*; use jsonrpc_tcp_server::jsonrpc_core::*; diff --git a/tcp/examples/tcp.rs b/tcp/examples/tcp.rs index ce3ffb473..1433d1a43 100644 --- a/tcp/examples/tcp.rs +++ b/tcp/examples/tcp.rs @@ -1,5 +1,4 @@ -extern crate jsonrpc_tcp_server; -extern crate env_logger; +use env_logger; use jsonrpc_tcp_server::ServerBuilder; use jsonrpc_tcp_server::jsonrpc_core::*; diff --git a/tcp/src/dispatch.rs b/tcp/src/dispatch.rs index ad0756e1d..50b50c303 100644 --- a/tcp/src/dispatch.rs +++ b/tcp/src/dispatch.rs @@ -3,8 +3,8 @@ use std::collections::HashMap; use std::net::SocketAddr; use std::sync::{Arc}; -use jsonrpc::futures::{Stream, Poll, Async, Sink, Future}; -use jsonrpc::futures::sync::mpsc; +use crate::jsonrpc::futures::{Stream, Poll, Async, Sink, Future}; +use crate::jsonrpc::futures::sync::mpsc; use parking_lot::Mutex; @@ -66,7 +66,7 @@ impl Dispatcher { match channels.get_mut(peer_addr) { Some(channel) => { // todo: maybe async here later? - try!(channel.send(msg).wait().map_err(|e| PushMessageError::from(e))); + channel.send(msg).wait().map_err(|e| PushMessageError::from(e))?; Ok(()) }, None => { diff --git a/tcp/src/lib.rs b/tcp/src/lib.rs index ae089c680..a90d6ce09 100644 --- a/tcp/src/lib.rs +++ b/tcp/src/lib.rs @@ -1,9 +1,6 @@ //! jsonrpc server over tcp/ip //! //! ```no_run -//! extern crate jsonrpc_core; -//! extern crate jsonrpc_tcp_server; -//! //! use jsonrpc_core::*; //! use jsonrpc_tcp_server::ServerBuilder; //! @@ -22,16 +19,13 @@ #![warn(missing_docs)] -extern crate jsonrpc_server_utils as server_utils; -extern crate parking_lot; -extern crate tokio_service; +use jsonrpc_server_utils as server_utils; -pub extern crate jsonrpc_core; +pub use jsonrpc_core; #[macro_use] extern crate log; #[cfg(test)] #[macro_use] extern crate lazy_static; -#[cfg(test)] extern crate env_logger; mod dispatch; mod meta; @@ -43,7 +37,7 @@ mod service; use jsonrpc_core as jsonrpc; -pub use dispatch::{Dispatcher, PushMessageError}; -pub use meta::{MetaExtractor, RequestContext}; -pub use server::{ServerBuilder, Server}; +pub use crate::dispatch::{Dispatcher, PushMessageError}; +pub use crate::meta::{MetaExtractor, RequestContext}; +pub use crate::server::{ServerBuilder, Server}; pub use self::server_utils::{tokio, codecs::Separator}; diff --git a/tcp/src/meta.rs b/tcp/src/meta.rs index 795fe9ead..6aac384c7 100644 --- a/tcp/src/meta.rs +++ b/tcp/src/meta.rs @@ -1,7 +1,7 @@ use std::net::SocketAddr; -use jsonrpc::futures::sync::mpsc; -use jsonrpc::Metadata; +use crate::jsonrpc::futures::sync::mpsc; +use crate::jsonrpc::Metadata; /// Request context pub struct RequestContext { diff --git a/tcp/src/server.rs b/tcp/src/server.rs index b5e6e7fbd..fcb2c74c0 100644 --- a/tcp/src/server.rs +++ b/tcp/src/server.rs @@ -4,18 +4,18 @@ use std::sync::Arc; use tokio_service::Service as TokioService; -use jsonrpc::{middleware, MetaIoHandler, Metadata, Middleware}; -use jsonrpc::futures::{future, Future, Stream, Sink}; -use jsonrpc::futures::sync::{mpsc, oneshot}; -use server_utils::{ +use crate::jsonrpc::{middleware, MetaIoHandler, Metadata, Middleware}; +use crate::jsonrpc::futures::{future, Future, Stream, Sink}; +use crate::jsonrpc::futures::sync::{mpsc, oneshot}; +use crate::server_utils::{ tokio_codec::Framed, tokio, reactor, codecs, SuspendableStream }; -use dispatch::{Dispatcher, SenderChannels, PeerMessageQueue}; -use meta::{MetaExtractor, RequestContext, NoopExtractor}; -use service::Service; +use crate::dispatch::{Dispatcher, SenderChannels, PeerMessageQueue}; +use crate::meta::{MetaExtractor, RequestContext, NoopExtractor}; +use crate::service::Service; /// TCP server builder pub struct ServerBuilder = middleware::Noop> { diff --git a/tcp/src/service.rs b/tcp/src/service.rs index 532f2d411..1c8cd7336 100644 --- a/tcp/src/service.rs +++ b/tcp/src/service.rs @@ -3,7 +3,7 @@ use std::net::SocketAddr; use tokio_service; -use jsonrpc::{middleware, FutureResult, Metadata, MetaIoHandler, Middleware}; +use crate::jsonrpc::{middleware, FutureResult, Metadata, MetaIoHandler, Middleware}; pub struct Service = middleware::Noop> { handler: Arc>, diff --git a/tcp/src/tests.rs b/tcp/src/tests.rs index 21326a4f2..a063ac3eb 100644 --- a/tcp/src/tests.rs +++ b/tcp/src/tests.rs @@ -3,10 +3,10 @@ use std::str::FromStr; use std::sync::Arc; use std::time::{Instant, Duration}; -use jsonrpc::{MetaIoHandler, Value, Metadata}; -use jsonrpc::futures::{self, Future, future}; +use crate::jsonrpc::{MetaIoHandler, Value, Metadata}; +use crate::jsonrpc::futures::{self, Future, future}; -use server_utils::tokio::{ +use crate::server_utils::tokio::{ timer::Delay, net::TcpStream, io::{self}, @@ -15,9 +15,9 @@ use server_utils::tokio::{ use parking_lot::Mutex; -use ServerBuilder; -use MetaExtractor; -use RequestContext; +use crate::ServerBuilder; +use crate::MetaExtractor; +use crate::RequestContext; fn casual_server() -> ServerBuilder { let mut io = MetaIoHandler::<()>::default(); @@ -29,7 +29,7 @@ fn casual_server() -> ServerBuilder { #[test] fn doc_test() { - ::logger::init_log(); + crate::logger::init_log(); let mut io = MetaIoHandler::<()>::default(); io.add_method("say_hello", |_params| { @@ -44,7 +44,7 @@ fn doc_test() { #[test] fn doc_test_connect() { - ::logger::init_log(); + crate::logger::init_log(); let addr: SocketAddr = "127.0.0.1:17775".parse().unwrap(); let server = casual_server(); let _server = server.start(&addr).expect("Server must run with no issues"); @@ -60,7 +60,7 @@ fn doc_test_connect() { #[test] fn disconnect() { - ::logger::init_log(); + crate::logger::init_log(); let addr: SocketAddr = "127.0.0.1:17777".parse().unwrap(); let server = casual_server(); let dispatcher = server.dispatcher(); @@ -106,7 +106,7 @@ fn dummy_request_str(addr: &SocketAddr, data: Vec) -> String { #[test] fn doc_test_handle() { - ::logger::init_log(); + crate::logger::init_log(); let addr: SocketAddr = "127.0.0.1:17780".parse().unwrap(); let server = casual_server(); @@ -128,7 +128,7 @@ fn doc_test_handle() { fn req_parallel() { use std::thread; - ::logger::init_log(); + crate::logger::init_log(); let addr: SocketAddr = "127.0.0.1:17782".parse().unwrap(); let server = casual_server(); let _server = server.start(&addr).expect("Server must run with no issues"); @@ -202,7 +202,7 @@ fn meta_server() -> ServerBuilder { #[test] fn peer_meta() { - ::logger::init_log(); + crate::logger::init_log(); let addr: SocketAddr = "127.0.0.1:17785".parse().unwrap(); let server = meta_server(); let _server = server.start(&addr).expect("Server must run with no issues"); @@ -236,7 +236,7 @@ impl MetaExtractor for PeerListMetaExtractor { #[test] fn message() { // MASSIVE SETUP - ::logger::init_log(); + crate::logger::init_log(); let addr: SocketAddr = "127.0.0.1:17790".parse().unwrap(); let mut io = MetaIoHandler::::default(); io.add_method_with_meta("say_hello", |_params, _: SocketMetadata| { diff --git a/test/Cargo.toml b/test/Cargo.toml index 1aed926d9..e28d0be7d 100644 --- a/test/Cargo.toml +++ b/test/Cargo.toml @@ -7,11 +7,14 @@ license = "MIT" homepage = "https://github.com/paritytech/jsonrpc" repository = "https://github.com/paritytech/jsonrpc" documentation = "https://paritytech.github.io/jsonrpc/jsonrpc_test/index.html" +edition = "2018" [dependencies] jsonrpc-core = { path = "../core", version = "10.0" } +jsonrpc-pubsub = { path = "../pubsub", version = "10.0" } serde = "1.0" serde_json = "1.0" [dev-dependencies] -jsonrpc-macros = { path = "../macros", version = "10.0" } +jsonrpc-derive = { path = "../derive", version = "10.0" } + diff --git a/test/src/lib.rs b/test/src/lib.rs index fbe03ccad..5015c07b7 100644 --- a/test/src/lib.rs +++ b/test/src/lib.rs @@ -1,21 +1,18 @@ //! An utility package to test jsonrpc-core based projects. //! //! ``` -//! #[macro_use] -//! extern crate jsonrpc_macros; +//! use jsonrpc_derive::rpc; +//! use jsonrpc_test as test; //! -//! extern crate jsonrpc_core as core; -//! extern crate jsonrpc_test as test; +//! use jsonrpc_core::{Result, Error, IoHandler}; //! -//! use core::Result; -//! -//! build_rpc_trait! { -//! pub trait Test { -//! #[rpc(name = "rpc_some_method")] -//! fn some_method(&self, u64) -> Result; -//! } +//! #[rpc] +//! pub trait Test { +//! #[rpc(name = "rpc_some_method")] +//! fn some_method(&self, _: u64) -> Result; //! } //! +//! //! struct Dummy; //! impl Test for Dummy { //! fn some_method(&self, x: u64) -> Result { @@ -32,9 +29,9 @@ //! //! // You can also test RPC created without macros: //! let rpc = { -//! let mut io = core::IoHandler::new(); +//! let mut io = IoHandler::new(); //! io.add_method("rpc_test_method", |_| { -//! Err(core::Error::internal_error()) +//! Err(Error::internal_error()) //! }); //! test::Rpc::from(io) //! }; @@ -49,8 +46,8 @@ #[warn(missing_docs)] extern crate jsonrpc_core as rpc; -extern crate serde; -extern crate serde_json; +use serde; +use serde_json; use std::collections::HashMap; diff --git a/ws/Cargo.toml b/ws/Cargo.toml index 7f0251e49..6dfe5ce15 100644 --- a/ws/Cargo.toml +++ b/ws/Cargo.toml @@ -7,6 +7,7 @@ license = "MIT" homepage = "https://github.com/paritytech/jsonrpc" repository = "https://github.com/paritytech/jsonrpc" documentation = "https://paritytech.github.io/jsonrpc/json_ws_server/index.html" +edition = "2018" [dependencies] error-chain = "0.12" diff --git a/ws/README.md b/ws/README.md index d8fb5b111..307df20f0 100644 --- a/ws/README.md +++ b/ws/README.md @@ -15,8 +15,6 @@ jsonrpc-ws-server = "10.0" `main.rs` ```rust -extern crate jsonrpc_ws_server; - use jsonrpc_ws_server::*; use jsonrpc_ws_server::jsonrpc_core::*; diff --git a/ws/examples/ws.rs b/ws/examples/ws.rs index dee6359c2..027fa5421 100644 --- a/ws/examples/ws.rs +++ b/ws/examples/ws.rs @@ -1,5 +1,3 @@ -extern crate jsonrpc_ws_server; - use jsonrpc_ws_server::ServerBuilder; use jsonrpc_ws_server::jsonrpc_core::*; diff --git a/ws/src/error.rs b/ws/src/error.rs index 2602eb770..c1b0ceea1 100644 --- a/ws/src/error.rs +++ b/ws/src/error.rs @@ -2,7 +2,7 @@ use std::io; -use ws; +use crate::ws; error_chain! { foreign_links { diff --git a/ws/src/lib.rs b/ws/src/lib.rs index 1823ebce9..733feb81c 100644 --- a/ws/src/lib.rs +++ b/ws/src/lib.rs @@ -2,12 +2,10 @@ #![warn(missing_docs)] -extern crate jsonrpc_server_utils as server_utils; -extern crate parking_lot; -extern crate slab; +use jsonrpc_server_utils as server_utils; -pub extern crate parity_ws as ws; -pub extern crate jsonrpc_core; +pub use parity_ws as ws; +pub use jsonrpc_core; #[macro_use] extern crate error_chain; diff --git a/ws/src/metadata.rs b/ws/src/metadata.rs index 60835c1d4..13dc750dd 100644 --- a/ws/src/metadata.rs +++ b/ws/src/metadata.rs @@ -1,13 +1,13 @@ use std::fmt; use std::sync::{atomic, Arc}; -use core::{self, futures}; -use core::futures::sync::mpsc; -use server_utils::{session, tokio::runtime::TaskExecutor}; -use ws; +use crate::core::{self, futures}; +use crate::core::futures::sync::mpsc; +use crate::server_utils::{session, tokio::runtime::TaskExecutor}; +use crate::ws; -use error; -use {Origin}; +use crate::error; +use crate::{Origin}; /// Output of WebSocket connection. Use this to send messages to the other endpoint. #[derive(Clone)] diff --git a/ws/src/server.rs b/ws/src/server.rs index e3d25441a..3fdeb93bb 100644 --- a/ws/src/server.rs +++ b/ws/src/server.rs @@ -3,16 +3,16 @@ use std::net::SocketAddr; use std::sync::{Arc, Mutex}; use std::thread; -use core; -use server_utils::cors::Origin; -use server_utils::hosts::{self, Host}; -use server_utils::reactor::{UninitializedExecutor, Executor}; -use server_utils::session::SessionStats; -use ws; - -use error::{Error, Result}; -use metadata; -use session; +use crate::core; +use crate::server_utils::cors::Origin; +use crate::server_utils::hosts::{self, Host}; +use crate::server_utils::reactor::{UninitializedExecutor, Executor}; +use crate::server_utils::session::SessionStats; +use crate::ws; + +use crate::error::{Error, Result}; +use crate::metadata; +use crate::session; /// `WebSockets` server implementation. pub struct Server { diff --git a/ws/src/server_builder.rs b/ws/src/server_builder.rs index 2a9760f44..1b6a0aed1 100644 --- a/ws/src/server_builder.rs +++ b/ws/src/server_builder.rs @@ -1,17 +1,17 @@ use std::net::SocketAddr; use std::sync::Arc; -use core; -use server_utils; -use server_utils::cors::Origin; -use server_utils::hosts::{Host, DomainsValidation}; -use server_utils::reactor::UninitializedExecutor; -use server_utils::session::SessionStats; +use crate::core; +use crate::server_utils; +use crate::server_utils::cors::Origin; +use crate::server_utils::hosts::{Host, DomainsValidation}; +use crate::server_utils::reactor::UninitializedExecutor; +use crate::server_utils::session::SessionStats; -use error::Result; -use metadata::{MetaExtractor, NoopExtractor}; -use server::Server; -use session; +use crate::error::Result; +use crate::metadata::{MetaExtractor, NoopExtractor}; +use crate::server::Server; +use crate::session; /// Builder for `WebSockets` server pub struct ServerBuilder> { diff --git a/ws/src/session.rs b/ws/src/session.rs index 512a10e0c..f3303cb52 100644 --- a/ws/src/session.rs +++ b/ws/src/session.rs @@ -1,22 +1,22 @@ use std; use std::sync::{atomic, Arc}; -use core; -use core::futures::{Async, Future, Poll}; -use core::futures::sync::oneshot; +use crate::core; +use crate::core::futures::{Async, Future, Poll}; +use crate::core::futures::sync::oneshot; use parking_lot::Mutex; use slab::Slab; -use server_utils::Pattern; -use server_utils::cors::Origin; -use server_utils::hosts::Host; -use server_utils::session::{SessionId, SessionStats}; -use server_utils::tokio::runtime::TaskExecutor; -use ws; +use crate::server_utils::Pattern; +use crate::server_utils::cors::Origin; +use crate::server_utils::hosts::Host; +use crate::server_utils::session::{SessionId, SessionStats}; +use crate::server_utils::tokio::runtime::TaskExecutor; +use crate::ws; -use error; -use metadata; +use crate::error; +use crate::metadata; /// Middleware to intercept server requests. /// You can either terminate the request (by returning a response) diff --git a/ws/src/tests.rs b/ws/src/tests.rs index 2667ebd31..e92874efb 100644 --- a/ws/src/tests.rs +++ b/ws/src/tests.rs @@ -6,13 +6,13 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::thread; use std::time::Duration; -use core; -use core::futures::Future; -use server_utils::hosts::DomainsValidation; -use ws; +use crate::core; +use crate::core::futures::Future; +use crate::server_utils::hosts::DomainsValidation; +use crate::ws; -use server::Server; -use server_builder::ServerBuilder; +use crate::server::Server; +use crate::server_builder::ServerBuilder; struct Response { status: String, @@ -62,7 +62,7 @@ fn request(server: Server, request: &str) -> Response { fn serve(port: u16) -> (Server, Arc) { use std::time::Duration; - use core::futures::sync::oneshot; + use crate::core::futures::sync::oneshot; let pending = Arc::new(AtomicUsize::new(0)); @@ -193,7 +193,7 @@ fn should_intercept_in_middleware() { #[test] fn drop_session_should_cancel() { - use ws::{connect, CloseCode}; + use crate::ws::{connect, CloseCode}; // given let (_server, incomplete) = serve(30005);