From b1e3acaf0c8bc1dc8f11d746d57ba354fbe4b0de Mon Sep 17 00:00:00 2001 From: David Date: Mon, 26 Aug 2019 12:09:44 +0200 Subject: [PATCH] [ipfs] Convert to edition 2018 (#10979) * [ipfs] Converto to edition 2018 Also: whitespace * Review feedback --- ipfs/Cargo.toml | 7 ++++--- ipfs/src/error.rs | 29 ++++++++++++++--------------- ipfs/src/lib.rs | 33 ++++++++++----------------------- ipfs/src/route.rs | 15 +++++++++------ 4 files changed, 37 insertions(+), 47 deletions(-) diff --git a/ipfs/Cargo.toml b/ipfs/Cargo.toml index 44902200e..4c20f87e8 100644 --- a/ipfs/Cargo.toml +++ b/ipfs/Cargo.toml @@ -4,15 +4,16 @@ name = "parity-ipfs-api" version = "1.12.0" license = "GPL-3.0" authors = ["Parity Technologies "] +edition = "2018" [dependencies] client-traits = { path = "../ethcore/client-traits" } common-types = { path = "../ethcore/types" } ethcore = { path = "../ethcore" } -parity-bytes = "0.1" +bytes = { package = "parity-bytes", version = "0.1"} ethereum-types = "0.6.0" -jsonrpc-core = "12.0.0" -jsonrpc-http-server = "12.0.0" +core = { package = "jsonrpc-core", version = "12.0.0"} +http = { package = "jsonrpc-http-server", version = "12.0.0"} rlp = "0.4.0" cid = "0.3" multihash = "0.8" diff --git a/ipfs/src/error.rs b/ipfs/src/error.rs index a9a584985..7250120c5 100644 --- a/ipfs/src/error.rs +++ b/ipfs/src/error.rs @@ -14,16 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use {multihash, cid, http}; -use route::Out; +use crate::route::Out; -pub type Result = ::std::result::Result; +pub type Result = std::result::Result; /// IPFS server error #[derive(Debug)] pub enum ServerError { /// Wrapped `std::io::Error` - IoError(::std::io::Error), + IoError(std::io::Error), /// Other `hyper` error Other(http::hyper::error::Error), /// Invalid --ipfs-api-interface @@ -31,8 +30,8 @@ pub enum ServerError { } /// Handle IO errors (ports taken when starting the server). -impl From<::std::io::Error> for ServerError { - fn from(err: ::std::io::Error) -> ServerError { +impl From for ServerError { + fn from(err: std::io::Error) -> ServerError { ServerError::IoError(err) } } @@ -53,17 +52,17 @@ impl From for String { } } -impl ::std::fmt::Display for ServerError { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - match self { - ServerError::IoError(err) => write!(f, "Io Error: {}", err), - ServerError::Other(err) => write!(f, "Other error: {}", err), - ServerError::InvalidInterface => write!(f, "Invalid interface"), - } - } +impl std::fmt::Display for ServerError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + ServerError::IoError(err) => write!(f, "Io Error: {}", err), + ServerError::Other(err) => write!(f, "Other error: {}", err), + ServerError::InvalidInterface => write!(f, "Invalid interface"), + } + } } -impl ::std::error::Error for ServerError {} +impl std::error::Error for ServerError {} #[derive(Debug, PartialEq)] pub enum Error { diff --git a/ipfs/src/lib.rs b/ipfs/src/lib.rs index 40ff2bd18..efd4dff69 100644 --- a/ipfs/src/lib.rs +++ b/ipfs/src/lib.rs @@ -14,19 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -extern crate multihash; -extern crate cid; -extern crate unicase; - -extern crate rlp; -extern crate client_traits; -extern crate common_types; -extern crate ethcore; -extern crate parity_bytes as bytes; -extern crate ethereum_types; -extern crate jsonrpc_core as core; -extern crate jsonrpc_http_server as http; - pub mod error; mod route; @@ -53,19 +40,19 @@ pub struct IpfsHandler { /// Hostnames allowed in the `Host` request header allowed_hosts: Option>, /// Reference to the Blockchain Client - client: Arc, + client: Arc, } impl IpfsHandler { - pub fn client(&self) -> &BlockChainClient { + pub fn client(&self) -> &dyn BlockChainClient { &*self.client } - pub fn new(cors: DomainsValidation, hosts: DomainsValidation, client: Arc) -> Self { + pub fn new(cors: DomainsValidation, hosts: DomainsValidation, client: Arc) -> Self { IpfsHandler { cors_domains: cors.into(), allowed_hosts: hosts.into(), - client: client, + client, } } pub fn on_request(&self, req: hyper::Request) -> (Option, Out) { @@ -156,7 +143,7 @@ pub fn start_server( interface: String, cors: DomainsValidation, hosts: DomainsValidation, - client: Arc + client: Arc ) -> Result { let ip: IpAddr = interface.parse().map_err(|_| ServerError::InvalidInterface)?; @@ -184,12 +171,12 @@ pub fn start_server( }; let server = server_bldr - .serve(new_service) - .map_err(|_| ()) - .select(shutdown_signal.map_err(|_| ())) - .then(|_| Ok(())); + .serve(new_service) + .map_err(|_| ()) + .select(shutdown_signal.map_err(|_| ())) + .then(|_| Ok(())); - hyper::rt::run(server); + hyper::rt::run(server); send(Ok(())); }); diff --git a/ipfs/src/route.rs b/ipfs/src/route.rs index 7d5fb926f..c974a0302 100644 --- a/ipfs/src/route.rs +++ b/ipfs/src/route.rs @@ -14,14 +14,17 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use {rlp, multihash, IpfsHandler}; -use error::{Error, Result}; -use cid::{ToCid, Codec}; +use crate::{ + IpfsHandler, + error::{Error, Result}, +}; -use common_types::ids::{BlockId, TransactionId}; -use multihash::Hash; -use ethereum_types::H256; use bytes::Bytes; +use cid::{ToCid, Codec}; +use common_types::ids::{BlockId, TransactionId}; +use ethereum_types::H256; +use multihash::{self, Hash}; +use rlp; type Reason = &'static str;