From 2704d2b28996808fe4d20138034e1af81ddc8b0e Mon Sep 17 00:00:00 2001 From: Sameer Puri <11097096+sameer@users.noreply.github.com> Date: Mon, 31 Dec 2018 16:29:00 -0500 Subject: Run cargo fmt --- ipfs-api/examples/add_tar.rs | 6 ++++-- ipfs-api/examples/bootstrap_default.rs | 6 ++++-- ipfs-api/examples/dns.rs | 6 ++++-- ipfs-api/examples/mfs.rs | 12 +++++++---- ipfs-api/examples/ping_peer.rs | 6 ++++-- ipfs-api/examples/pubsub.rs | 3 ++- ipfs-api/src/client.rs | 39 +++++++++++++++++----------------- ipfs-api/src/response/error.rs | 5 +---- ipfs-cli/src/command/mod.rs | 7 ++++-- 9 files changed, 52 insertions(+), 38 deletions(-) diff --git a/ipfs-api/examples/add_tar.rs b/ipfs-api/examples/add_tar.rs index 1dc3b61..1880712 100644 --- a/ipfs-api/examples/add_tar.rs +++ b/ipfs-api/examples/add_tar.rs @@ -45,10 +45,12 @@ fn main() { println!(); client.tar_cat(&add.hash[..]).concat2() - }).map(|cat| { + }) + .map(|cat| { println!("{}", String::from_utf8_lossy(&cat[..])); println!(); - }).map_err(|e| eprintln!("{}", e)); + }) + .map_err(|e| eprintln!("{}", e)); hyper::rt::run(req) } diff --git a/ipfs-api/examples/bootstrap_default.rs b/ipfs-api/examples/bootstrap_default.rs index 1d6d75c..6ba9575 100644 --- a/ipfs-api/examples/bootstrap_default.rs +++ b/ipfs-api/examples/bootstrap_default.rs @@ -49,11 +49,13 @@ fn main() { println!("dropping all bootstrap peers..."); drop - }).and_then(|_| { + }) + .and_then(|_| { println!(); println!("adding default peers..."); add - }).map_err(|e| eprintln!("{}", e)), + }) + .map_err(|e| eprintln!("{}", e)), ); } diff --git a/ipfs-api/examples/dns.rs b/ipfs-api/examples/dns.rs index 2bbb92a..78b4086 100644 --- a/ipfs-api/examples/dns.rs +++ b/ipfs-api/examples/dns.rs @@ -27,14 +27,16 @@ fn main() { println!(); client.file_ls(&dns.path[..]) - }).map(|contents| { + }) + .map(|contents| { println!("found contents:"); for directory in contents.objects.values() { for file in directory.links.iter() { println!("[{}] ({} bytes)", file.name, file.size); } } - }).map_err(|e| eprintln!("{}", e)); + }) + .map_err(|e| eprintln!("{}", e)); hyper::rt::run(req); } diff --git a/ipfs-api/examples/mfs.rs b/ipfs-api/examples/mfs.rs index 2a99bea..8bea192 100644 --- a/ipfs-api/examples/mfs.rs +++ b/ipfs-api/examples/mfs.rs @@ -53,19 +53,22 @@ fn main() { println!(); mkdir_recursive - }).and_then(|_| { + }) + .and_then(|_| { println!("getting status of /test/does..."); println!(); file_stat - }).and_then(|stat| { + }) + .and_then(|stat| { print_stat(stat); println!("writing source file to /test/mfs.rs"); println!(); file_write - }).and_then(|_| file_write_stat) + }) + .and_then(|_| file_write_stat) .and_then(|stat| { print_stat(stat); @@ -73,7 +76,8 @@ fn main() { println!(); file_rm - }).map(|_| println!("done!")) + }) + .map(|_| println!("done!")) .map_err(|e| eprintln!("{}", e)), ) } diff --git a/ipfs-api/examples/ping_peer.rs b/ipfs-api/examples/ping_peer.rs index 9cd7835..1d32210 100644 --- a/ipfs-api/examples/ping_peer.rs +++ b/ipfs-api/examples/ping_peer.rs @@ -51,11 +51,13 @@ fn main() { ping_gather }) - }).map(|pings: Vec| { + }) + .map(|pings: Vec| { for ping in pings.iter() { println!("got response ({:?}) at ({})...", ping.text, ping.time); } - }).map_err(|e| eprintln!("{}", e)); + }) + .map_err(|e| eprintln!("{}", e)); hyper::rt::run(req); } diff --git a/ipfs-api/examples/pubsub.rs b/ipfs-api/examples/pubsub.rs index f773841..10ee0c5 100644 --- a/ipfs-api/examples/pubsub.rs +++ b/ipfs-api/examples/pubsub.rs @@ -68,7 +68,8 @@ fn main() { println!("received ({:?})", msg); Ok(()) - }).map_err(|e| eprintln!("{}", e)), + }) + .map_err(|e| eprintln!("{}", e)), ) } } diff --git a/ipfs-api/src/client.rs b/ipfs-api/src/client.rs index 430612e..2613541 100644 --- a/ipfs-api/src/client.rs +++ b/ipfs-api/src/client.rs @@ -7,9 +7,9 @@ // use futures::{ + future, stream::{self, Stream}, Future, IntoFuture, - future, }; use header::TRAILER; use http::uri::InvalidUri; @@ -163,7 +163,8 @@ impl IpfsClient { let status = res.status(); res.into_body().concat2().map(move |chunk| (status, chunk)) - }).from_err(); + }) + .from_err(); Box::new(res) } @@ -192,25 +193,25 @@ impl IpfsClient { .request(req) .from_err() .map(move |res| { - let stream: Box< - Stream + Send + 'static, - > = match res.status() { - StatusCode::OK => process(res), - // If the server responded with an error status code, the body - // still needs to be read so an error can be built. This block will - // read the entire body stream, then immediately return an error. - // - _ => Box::new( - res.into_body() - .concat2() - .from_err() - .and_then(|chunk| Err(Self::build_error_from_body(chunk))) - .into_stream(), - ), - }; + let stream: Box + Send + 'static> = + match res.status() { + StatusCode::OK => process(res), + // If the server responded with an error status code, the body + // still needs to be read so an error can be built. This block will + // read the entire body stream, then immediately return an error. + // + _ => Box::new( + res.into_body() + .concat2() + .from_err() + .and_then(|chunk| Err(Self::build_error_from_body(chunk))) + .into_stream(), + ), + }; stream - }).flatten_stream(); + }) + .flatten_stream(); Box::new(res) } diff --git a/ipfs-api/src/response/error.rs b/ipfs-api/src/response/error.rs index 8e43d51..94f7fa9 100644 --- a/ipfs-api/src/response/error.rs +++ b/ipfs-api/src/response/error.rs @@ -54,10 +54,7 @@ pub enum Error { StreamError(String), /// API returned a trailer header with unrecognized value. - #[fail( - display = "api returned a trailer header with unknown value: '{}'", - _0 - )] + #[fail(display = "api returned a trailer header with unknown value: '{}'", _0)] UnrecognizedTrailerHeader(String), #[fail(display = "api returned unknwon error '{}'", _0)] diff --git a/ipfs-cli/src/command/mod.rs b/ipfs-cli/src/command/mod.rs index 969f872..86f9aa5 100644 --- a/ipfs-cli/src/command/mod.rs +++ b/ipfs-cli/src/command/mod.rs @@ -6,12 +6,12 @@ // copied, modified, or distributed except according to those terms. // -use std::path::Path; use clap::{App, ArgMatches}; use futures::Future; use ipfs_api::IpfsClient; use std::error::Error; use std::fs; +use std::path::Path; pub type CommandExecutable = Box + 'static + Send>; @@ -19,7 +19,10 @@ pub const EXPECTED_FILE: &str = "expected to read input file"; /// Verifies that a path points to a file that exists, and not a directory. /// -pub fn verify_file

(path: P) -> Result<(), String> where P: AsRef { +pub fn verify_file

(path: P) -> Result<(), String> +where + P: AsRef, +{ match fs::metadata(path) { Ok(ref metadata) if metadata.is_file() => Ok(()), Ok(_) => Err("file must not be a directory".into()), -- cgit v1.2.3