From 3a2b3a8cb9ec71e07faaae59fb144151eb997fdc Mon Sep 17 00:00:00 2001 From: Ferris Tseng Date: Sat, 4 Aug 2018 12:19:25 -0400 Subject: formatting --- ipfs-api/examples/add_file.rs | 2 +- ipfs-api/examples/add_tar.rs | 6 +-- ipfs-api/examples/bootstrap_default.rs | 8 ++-- ipfs-api/examples/dns.rs | 6 +-- ipfs-api/examples/mfs.rs | 12 ++---- ipfs-api/examples/ping_peer.rs | 8 ++-- ipfs-api/examples/pubsub.rs | 8 ++-- ipfs-api/src/client.rs | 39 +++++++++++++------- ipfs-api/src/lib.rs | 4 +- ipfs-api/src/read.rs | 12 +++--- ipfs-api/src/request/mod.rs | 8 ++-- ipfs-api/src/response/error.rs | 67 ++++++++++++++++++++-------------- 12 files changed, 97 insertions(+), 83 deletions(-) diff --git a/ipfs-api/examples/add_file.rs b/ipfs-api/examples/add_file.rs index 7784c89..d771966 100644 --- a/ipfs-api/examples/add_file.rs +++ b/ipfs-api/examples/add_file.rs @@ -10,8 +10,8 @@ extern crate futures; extern crate hyper; extern crate ipfs_api; -use ipfs_api::IpfsClient; use futures::Future; +use ipfs_api::IpfsClient; use std::fs::File; // Creates an Ipfs client, and adds this source file to Ipfs. diff --git a/ipfs-api/examples/add_tar.rs b/ipfs-api/examples/add_tar.rs index 1880712..1dc3b61 100644 --- a/ipfs-api/examples/add_tar.rs +++ b/ipfs-api/examples/add_tar.rs @@ -45,12 +45,10 @@ 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 79c66ab..1d6d75c 100644 --- a/ipfs-api/examples/bootstrap_default.rs +++ b/ipfs-api/examples/bootstrap_default.rs @@ -10,8 +10,8 @@ extern crate futures; extern crate hyper; extern crate ipfs_api; -use ipfs_api::IpfsClient; use futures::Future; +use ipfs_api::IpfsClient; // Lists clients in bootstrap list, then adds the default list, then removes // them, and readds them. @@ -49,13 +49,11 @@ 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 78b4086..2bbb92a 100644 --- a/ipfs-api/examples/dns.rs +++ b/ipfs-api/examples/dns.rs @@ -27,16 +27,14 @@ 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 8bea192..2a99bea 100644 --- a/ipfs-api/examples/mfs.rs +++ b/ipfs-api/examples/mfs.rs @@ -53,22 +53,19 @@ 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); @@ -76,8 +73,7 @@ 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 be55dd5..9cd7835 100644 --- a/ipfs-api/examples/ping_peer.rs +++ b/ipfs-api/examples/ping_peer.rs @@ -11,7 +11,7 @@ extern crate hyper; extern crate ipfs_api; use futures::{Future, Stream}; -use ipfs_api::{IpfsClient, response::PingResponse}; +use ipfs_api::{response::PingResponse, IpfsClient}; // Creates an Ipfs client, discovers a connected peer, and pings it using the // streaming Api, and by collecting it into a collection. @@ -51,13 +51,11 @@ 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 876ec04..f773841 100644 --- a/ipfs-api/examples/pubsub.rs +++ b/ipfs-api/examples/pubsub.rs @@ -13,7 +13,10 @@ extern crate tokio_timer; use futures::{Future, Stream}; use ipfs_api::IpfsClient; -use std::{thread, time::{Duration, Instant}}; +use std::{ + thread, + time::{Duration, Instant}, +}; use tokio_timer::Interval; static TOPIC: &'static str = "test"; @@ -65,8 +68,7 @@ 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 c933e89..92946ea 100644 --- a/ipfs-api/src/client.rs +++ b/ipfs-api/src/client.rs @@ -6,14 +6,21 @@ // copied, modified, or distributed except according to those terms. // -use futures::{Future, IntoFuture, stream::{self, Stream}}; +use futures::{ + stream::{self, Stream}, + Future, IntoFuture, +}; use header::TRAILER; +use http::uri::InvalidUri; +use hyper::{ + self, + client::{Client, HttpConnector}, + Chunk, Request, Response, StatusCode, Uri, +}; +use hyper_multipart::client::multipart; use read::{JsonLineDecoder, LineDecoder, StreamReader}; use request::{self, ApiRequest}; use response::{self, Error}; -use http::uri::InvalidUri; -use hyper::{self, Chunk, Request, Response, StatusCode, Uri, client::{Client, HttpConnector}}; -use hyper_multipart::client::multipart; use serde::{Deserialize, Serialize}; use serde_json; use std::io::Read; @@ -147,14 +154,14 @@ impl IpfsClient { { match self.build_base_request(req, form) { Ok(req) => { - let res = self.client + let res = self + .client .request(req) .and_then(|res| { let status = res.status(); res.into_body().concat2().map(move |chunk| (status, chunk)) - }) - .from_err(); + }).from_err(); Box::new(res) } @@ -178,7 +185,8 @@ impl IpfsClient { { match self.build_base_request(req, form) { Ok(req) => { - let res = self.client + let res = self + .client .request(req) .from_err() .map(move |res| { @@ -200,8 +208,7 @@ impl IpfsClient { }; stream - }) - .flatten_stream(); + }).flatten_stream(); Box::new(res) } @@ -217,7 +224,8 @@ impl IpfsClient { Req: ApiRequest + Serialize, for<'de> Res: 'static + Deserialize<'de> + Send, { - let res = self.request_raw(req, form) + let res = self + .request_raw(req, form) .and_then(|(status, chunk)| IpfsClient::process_json_response(status, chunk)); Box::new(res) @@ -230,7 +238,8 @@ impl IpfsClient { where Req: ApiRequest + Serialize, { - let res = self.request_raw(req, form) + let res = self + .request_raw(req, form) .and_then(|(status, chunk)| match status { StatusCode::OK => Ok(()), _ => Err(Self::build_error_from_body(chunk)), @@ -246,7 +255,8 @@ impl IpfsClient { where Req: ApiRequest + Serialize, { - let res = self.request_raw(req, form) + let res = self + .request_raw(req, form) .and_then(|(status, chunk)| match status { StatusCode::OK => String::from_utf8(chunk.to_vec()).map_err(From::from), _ => Err(Self::build_error_from_body(chunk)), @@ -1396,7 +1406,8 @@ impl IpfsClient { /// ``` /// pub fn log_tail(&self) -> AsyncStreamResponse { - let res = self.build_base_request(&request::LogTail, None) + let res = self + .build_base_request(&request::LogTail, None) .map(|req| self.client.request(req).from_err()) .into_future() .flatten() diff --git a/ipfs-api/src/lib.rs b/ipfs-api/src/lib.rs index 8c7f74f..aa95495 100644 --- a/ipfs-api/src/lib.rs +++ b/ipfs-api/src/lib.rs @@ -101,8 +101,8 @@ extern crate tokio_io; pub use client::IpfsClient; pub use request::{KeyType, Logger, LoggingLevel, ObjectTemplate}; -mod request; -pub mod response; mod client; mod header; mod read; +mod request; +pub mod response; diff --git a/ipfs-api/src/read.rs b/ipfs-api/src/read.rs index 513a3ac..674d5fa 100644 --- a/ipfs-api/src/read.rs +++ b/ipfs-api/src/read.rs @@ -13,7 +13,11 @@ use hyper::Chunk; use response::Error; use serde::Deserialize; use serde_json; -use std::{cmp, io::{self, Read}, marker::PhantomData}; +use std::{ + cmp, + io::{self, Read}, + marker::PhantomData, +}; use tokio_codec::Decoder; use tokio_io::AsyncRead; @@ -199,8 +203,4 @@ where } } -impl AsyncRead for StreamReader -where - S: Stream, -{ -} +impl AsyncRead for StreamReader where S: Stream {} diff --git a/ipfs-api/src/request/mod.rs b/ipfs-api/src/request/mod.rs index d8c1660..947a912 100644 --- a/ipfs-api/src/request/mod.rs +++ b/ipfs-api/src/request/mod.rs @@ -21,10 +21,10 @@ pub use self::file::*; pub use self::files::*; pub use self::filestore::*; pub use self::get::*; -pub use self::log::*; -pub use self::ls::*; pub use self::id::*; pub use self::key::*; +pub use self::log::*; +pub use self::ls::*; pub use self::name::*; pub use self::object::*; pub use self::pin::*; @@ -82,10 +82,10 @@ mod file; mod files; mod filestore; mod get; -mod log; -mod ls; mod id; mod key; +mod log; +mod ls; mod name; mod object; mod pin; diff --git a/ipfs-api/src/response/error.rs b/ipfs-api/src/response/error.rs index 474275c..8e43d51 100644 --- a/ipfs-api/src/response/error.rs +++ b/ipfs-api/src/response/error.rs @@ -10,8 +10,8 @@ use http; use hyper; use serde_json; use serde_urlencoded; -use std::string::FromUtf8Error; use std; +use std::string::FromUtf8Error; #[derive(Fail, Debug, Deserialize)] #[serde(rename_all = "PascalCase")] @@ -23,32 +23,45 @@ pub struct ApiError { #[derive(Fail, Debug)] pub enum Error { - // Foreign errors. - #[fail(display = "hyper client error '{}'", _0)] - Client(hyper::Error), - #[fail(display = "http error '{}'", _0)] - Http(http::Error), - #[fail(display = "json parse error '{}'", _0)] - Parse(serde_json::Error), - #[fail(display = "utf8 decoding error '{}'", _0)] - ParseUtf8(FromUtf8Error), - #[fail(display = "uri error '{}'", _0)] - Url(http::uri::InvalidUri), - #[fail(display = "io error '{}'", _0)] - Io(std::io::Error), - #[fail(display = "url encoding error '{}'", _0)] - EncodeUrl(serde_urlencoded::ser::Error), - /// An error returned by the Ipfs api. - #[fail(display = "api returned error '{}'", _0)] - Api(ApiError), - /// A stream error indicated in the Trailer header. - #[fail(display = "api returned an error while streaming: '{}'", _0)] - StreamError(String), - /// API returned a trailer header with unrecognized value. - #[fail(display = "api returned a trailer header with unknown value: '{}'", _0)] - UnrecognizedTrailerHeader(String), - #[fail(display = "api returned unknwon error '{}'", _0)] - Uncategorized(String), + // Foreign errors. + #[fail(display = "hyper client error '{}'", _0)] + Client(hyper::Error), + + #[fail(display = "http error '{}'", _0)] + Http(http::Error), + + #[fail(display = "json parse error '{}'", _0)] + Parse(serde_json::Error), + + #[fail(display = "utf8 decoding error '{}'", _0)] + ParseUtf8(FromUtf8Error), + + #[fail(display = "uri error '{}'", _0)] + Url(http::uri::InvalidUri), + + #[fail(display = "io error '{}'", _0)] + Io(std::io::Error), + + #[fail(display = "url encoding error '{}'", _0)] + EncodeUrl(serde_urlencoded::ser::Error), + + /// An error returned by the Ipfs api. + #[fail(display = "api returned error '{}'", _0)] + Api(ApiError), + + /// A stream error indicated in the Trailer header. + #[fail(display = "api returned an error while streaming: '{}'", _0)] + StreamError(String), + + /// API returned a trailer header with unrecognized value. + #[fail( + display = "api returned a trailer header with unknown value: '{}'", + _0 + )] + UnrecognizedTrailerHeader(String), + + #[fail(display = "api returned unknwon error '{}'", _0)] + Uncategorized(String), } impl From for Error { -- cgit v1.2.3