From d53e6d335c3cfde51f6ceebd2da5306f5ed86ce8 Mon Sep 17 00:00:00 2001 From: Julius Michaelis Date: Tue, 19 Jan 2021 00:30:38 +0900 Subject: Reorganize features --- README.md | 2 +- ipfs-api/Cargo.toml | 12 +++++-- ipfs-api/examples/add_file.rs | 4 +-- ipfs-api/examples/add_tar.rs | 4 +-- ipfs-api/examples/bootstrap_default.rs | 4 +-- ipfs-api/examples/config.rs | 4 +-- ipfs-api/examples/dag.rs | 4 +-- ipfs-api/examples/dns.rs | 4 +-- ipfs-api/examples/get_commands.rs | 4 +-- ipfs-api/examples/get_stats.rs | 4 +-- ipfs-api/examples/get_swarm.rs | 4 +-- ipfs-api/examples/get_version.rs | 4 +-- ipfs-api/examples/log_tail.rs | 4 +-- ipfs-api/examples/mfs.rs | 4 +-- ipfs-api/examples/ping_peer.rs | 4 +-- ipfs-api/examples/pubsub.rs | 4 +-- ipfs-api/examples/replace_config.rs | 4 +-- ipfs-api/examples/resolve_name.rs | 4 +-- ipfs-api/src/client/internal.rs | 66 +++++++++++++++++----------------- ipfs-api/src/lib.rs | 43 +++++++++++----------- ipfs-api/src/request/add.rs | 22 ++++++------ ipfs-api/src/request/files.rs | 60 +++++++++++++++---------------- ipfs-api/src/request/ls.rs | 8 ++--- ipfs-api/src/response/error.rs | 66 +++++++++++++++++----------------- 24 files changed, 176 insertions(+), 167 deletions(-) diff --git a/README.md b/README.md index 0c71be8..baf10f9 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ You can use `actix-web` as a backend instead of `hyper`. ```toml [dependencies] -ipfs-api = { version = "0.9.0", features = ["actix"], default-features = false } +ipfs-api = { version = "0.9.0", features = ["with-actix"], default-features = false } ``` ### Examples diff --git a/ipfs-api/Cargo.toml b/ipfs-api/Cargo.toml index 2fba349..1520c95 100644 --- a/ipfs-api/Cargo.toml +++ b/ipfs-api/Cargo.toml @@ -15,9 +15,15 @@ license = "MIT OR Apache-2.0" travis-ci = { repository = "ferristseng/rust-ipfs-api" } [features] -default = ["hyper", "hyper-multipart-rfc7578", "hyper-tls", "failure"] -actix = ["actix-http", "actix-multipart-rfc7578", "awc", "derive_more"] -builder = ["typed-builder"] +default = ["with-hyper-tls", "with-builder"] +with-hyper-tls = ["with-hyper", "hyper-tls"] +with-hyper-rustls = ["with-hyper", "hyper-rustls"] +with-hyper = ["hyper", "hyper-multipart-rfc7578", "failure"] +with-actix = ["actix-http", "actix-multipart-rfc7578", "awc", "derive_more"] +with-builder = ["typed-builder"] +# Old features, kept for compatibility +actix = ["with-actix"] +builder = ["with-builder"] [dependencies] actix-http = { version = "1.0", optional = true } diff --git a/ipfs-api/examples/add_file.rs b/ipfs-api/examples/add_file.rs index 3015684..5917884 100644 --- a/ipfs-api/examples/add_file.rs +++ b/ipfs-api/examples/add_file.rs @@ -11,8 +11,8 @@ use std::fs::File; // Creates an Ipfs client, and adds this source file to Ipfs. // -#[cfg_attr(feature = "actix", actix_rt::main)] -#[cfg_attr(feature = "hyper", tokio::main)] +#[cfg_attr(feature = "with-actix", actix_rt::main)] +#[cfg_attr(feature = "with-hyper", tokio::main)] async fn main() { eprintln!("note: this must be run in the root of the project repository"); eprintln!("connecting to localhost:5001..."); diff --git a/ipfs-api/examples/add_tar.rs b/ipfs-api/examples/add_tar.rs index 0bf0eb9..a89c805 100644 --- a/ipfs-api/examples/add_tar.rs +++ b/ipfs-api/examples/add_tar.rs @@ -13,8 +13,8 @@ use tar::Builder; // Creates an Ipfs client, and adds this source file to Ipfs. // -#[cfg_attr(feature = "actix", actix_rt::main)] -#[cfg_attr(feature = "hyper", tokio::main)] +#[cfg_attr(feature = "with-actix", actix_rt::main)] +#[cfg_attr(feature = "with-hyper", tokio::main)] async fn main() { eprintln!("note: this must be run in the root of the project repository"); eprintln!("connecting to localhost:5001..."); diff --git a/ipfs-api/examples/bootstrap_default.rs b/ipfs-api/examples/bootstrap_default.rs index 9377c49..8dc3772 100644 --- a/ipfs-api/examples/bootstrap_default.rs +++ b/ipfs-api/examples/bootstrap_default.rs @@ -11,8 +11,8 @@ use ipfs_api::IpfsClient; // Lists clients in bootstrap list, then adds the default list, then removes // them, and readds them. // -#[cfg_attr(feature = "actix", actix_rt::main)] -#[cfg_attr(feature = "hyper", tokio::main)] +#[cfg_attr(feature = "with-actix", actix_rt::main)] +#[cfg_attr(feature = "with-hyper", tokio::main)] async fn main() { eprintln!("connecting to localhost:5001..."); diff --git a/ipfs-api/examples/config.rs b/ipfs-api/examples/config.rs index 884ecb4..3964146 100644 --- a/ipfs-api/examples/config.rs +++ b/ipfs-api/examples/config.rs @@ -10,8 +10,8 @@ use ipfs_api::IpfsClient; // Creates an Ipfs client, read & set config values. // -#[cfg_attr(feature = "actix", actix_rt::main)] -#[cfg_attr(feature = "hyper", tokio::main)] +#[cfg_attr(feature = "with-actix", actix_rt::main)] +#[cfg_attr(feature = "with-hyper", tokio::main)] async fn main() { eprintln!("note: this must be run in the root of the project repository"); eprintln!("connecting to localhost:5001..."); diff --git a/ipfs-api/examples/dag.rs b/ipfs-api/examples/dag.rs index 9dff2bb..20d7bef 100644 --- a/ipfs-api/examples/dag.rs +++ b/ipfs-api/examples/dag.rs @@ -12,8 +12,8 @@ use std::io::Cursor; // Creates an Ipfs client, and adds this dag object to Ipfs then fetch it back. // -#[cfg_attr(feature = "actix", actix_rt::main)] -#[cfg_attr(feature = "hyper", tokio::main)] +#[cfg_attr(feature = "with-actix", actix_rt::main)] +#[cfg_attr(feature = "with-hyper", tokio::main)] async fn main() { eprintln!("note: this must be run in the root of the project repository"); eprintln!("connecting to localhost:5001..."); diff --git a/ipfs-api/examples/dns.rs b/ipfs-api/examples/dns.rs index 02857e0..a9b0604 100644 --- a/ipfs-api/examples/dns.rs +++ b/ipfs-api/examples/dns.rs @@ -10,8 +10,8 @@ use ipfs_api::IpfsClient; // Creates an Ipfs client, resolves ipfs.io, and lists the contents of it. // -#[cfg_attr(feature = "actix", actix_rt::main)] -#[cfg_attr(feature = "hyper", tokio::main)] +#[cfg_attr(feature = "with-actix", actix_rt::main)] +#[cfg_attr(feature = "with-hyper", tokio::main)] async fn main() { eprintln!("connecting to localhost:5001..."); diff --git a/ipfs-api/examples/get_commands.rs b/ipfs-api/examples/get_commands.rs index 4aa91ce..5ca7b00 100644 --- a/ipfs-api/examples/get_commands.rs +++ b/ipfs-api/examples/get_commands.rs @@ -32,8 +32,8 @@ fn print_recursive(indent: usize, cmd: &response::CommandsResponse) { // Creates an Ipfs client, and gets a list of available commands from the // Ipfs server. // -#[cfg_attr(feature = "actix", actix_rt::main)] -#[cfg_attr(feature = "hyper", tokio::main)] +#[cfg_attr(feature = "with-actix", actix_rt::main)] +#[cfg_attr(feature = "with-hyper", tokio::main)] async fn main() { eprintln!("connecting to localhost:5001..."); diff --git a/ipfs-api/examples/get_stats.rs b/ipfs-api/examples/get_stats.rs index f6eef0f..c2b6835 100644 --- a/ipfs-api/examples/get_stats.rs +++ b/ipfs-api/examples/get_stats.rs @@ -10,8 +10,8 @@ use ipfs_api::IpfsClient; // Creates an Ipfs client, and gets some stats about the Ipfs server. // -#[cfg_attr(feature = "actix", actix_rt::main)] -#[cfg_attr(feature = "hyper", tokio::main)] +#[cfg_attr(feature = "with-actix", actix_rt::main)] +#[cfg_attr(feature = "with-hyper", tokio::main)] async fn main() { eprintln!("connecting to localhost:5001..."); diff --git a/ipfs-api/examples/get_swarm.rs b/ipfs-api/examples/get_swarm.rs index 67dc70b..114f70e 100644 --- a/ipfs-api/examples/get_swarm.rs +++ b/ipfs-api/examples/get_swarm.rs @@ -11,8 +11,8 @@ use ipfs_api::IpfsClient; // Creates an Ipfs client, and gets information about your local address, and // connected peers. // -#[cfg_attr(feature = "actix", actix_rt::main)] -#[cfg_attr(feature = "hyper", tokio::main)] +#[cfg_attr(feature = "with-actix", actix_rt::main)] +#[cfg_attr(feature = "with-hyper", tokio::main)] async fn main() { eprintln!("connecting to localhost:5001..."); diff --git a/ipfs-api/examples/get_version.rs b/ipfs-api/examples/get_version.rs index 9d22988..bc91f50 100644 --- a/ipfs-api/examples/get_version.rs +++ b/ipfs-api/examples/get_version.rs @@ -10,8 +10,8 @@ use ipfs_api::IpfsClient; // Creates an Ipfs client, and gets the version of the Ipfs server. // -#[cfg_attr(feature = "actix", actix_rt::main)] -#[cfg_attr(feature = "hyper", tokio::main)] +#[cfg_attr(feature = "with-actix", actix_rt::main)] +#[cfg_attr(feature = "with-hyper", tokio::main)] async fn main() { eprintln!("connecting to localhost:5001..."); diff --git a/ipfs-api/examples/log_tail.rs b/ipfs-api/examples/log_tail.rs index 79b6e65..2e4955a 100644 --- a/ipfs-api/examples/log_tail.rs +++ b/ipfs-api/examples/log_tail.rs @@ -11,8 +11,8 @@ use ipfs_api::IpfsClient; // Tails the log of IPFS. // -#[cfg_attr(feature = "actix", actix_rt::main)] -#[cfg_attr(feature = "hyper", tokio::main)] +#[cfg_attr(feature = "with-actix", actix_rt::main)] +#[cfg_attr(feature = "with-hyper", tokio::main)] async fn main() { eprintln!("connecting to localhost:5001..."); diff --git a/ipfs-api/examples/mfs.rs b/ipfs-api/examples/mfs.rs index 3d6419c..85dd0f7 100644 --- a/ipfs-api/examples/mfs.rs +++ b/ipfs-api/examples/mfs.rs @@ -20,8 +20,8 @@ fn print_stat(stat: response::FilesStatResponse) { // Creates an Ipfs client, and makes some calls to the Mfs Api. // -#[cfg_attr(feature = "actix", actix_rt::main)] -#[cfg_attr(feature = "hyper", tokio::main)] +#[cfg_attr(feature = "with-actix", actix_rt::main)] +#[cfg_attr(feature = "with-hyper", tokio::main)] async fn main() { eprintln!("note: this must be run in the root of the project repository"); eprintln!("connecting to localhost:5001..."); diff --git a/ipfs-api/examples/ping_peer.rs b/ipfs-api/examples/ping_peer.rs index 2934c16..08b0496 100644 --- a/ipfs-api/examples/ping_peer.rs +++ b/ipfs-api/examples/ping_peer.rs @@ -12,8 +12,8 @@ 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. // -#[cfg_attr(feature = "actix", actix_rt::main)] -#[cfg_attr(feature = "hyper", tokio::main)] +#[cfg_attr(feature = "with-actix", actix_rt::main)] +#[cfg_attr(feature = "with-hyper", tokio::main)] async fn main() { eprintln!("connecting to localhost:5001..."); diff --git a/ipfs-api/examples/pubsub.rs b/ipfs-api/examples/pubsub.rs index 465b86b..6fef446 100644 --- a/ipfs-api/examples/pubsub.rs +++ b/ipfs-api/examples/pubsub.rs @@ -25,8 +25,8 @@ fn get_client() -> IpfsClient { // Creates an Ipfs client, and simultaneously publishes and reads from a pubsub // topic. // -#[cfg_attr(feature = "actix", actix_rt::main)] -#[cfg_attr(feature = "hyper", tokio::main)] +#[cfg_attr(feature = "with-actix", actix_rt::main)] +#[cfg_attr(feature = "with-hyper", tokio::main)] async fn main() { eprintln!("note: ipfs must be run with the --enable-pubsub-experiment flag"); diff --git a/ipfs-api/examples/replace_config.rs b/ipfs-api/examples/replace_config.rs index 76cc96f..372609b 100644 --- a/ipfs-api/examples/replace_config.rs +++ b/ipfs-api/examples/replace_config.rs @@ -11,8 +11,8 @@ use std::io::Cursor; // Creates an Ipfs client, and replaces the config file with the default one. // -#[cfg_attr(feature = "actix", actix_rt::main)] -#[cfg_attr(feature = "hyper", tokio::main)] +#[cfg_attr(feature = "with-actix", actix_rt::main)] +#[cfg_attr(feature = "with-hyper", tokio::main)] async fn main() { eprintln!("note: this must be run in the root of the project repository"); eprintln!("connecting to localhost:5001..."); diff --git a/ipfs-api/examples/resolve_name.rs b/ipfs-api/examples/resolve_name.rs index 0d7b830..57ad10e 100644 --- a/ipfs-api/examples/resolve_name.rs +++ b/ipfs-api/examples/resolve_name.rs @@ -13,8 +13,8 @@ const IPFS_IPNS: &str = "/ipns/ipfs.io"; // Creates an Ipfs client, and resolves the Ipfs domain name, and // publishes a path to Ipns. // -#[cfg_attr(feature = "actix", actix_rt::main)] -#[cfg_attr(feature = "hyper", tokio::main)] +#[cfg_attr(feature = "with-actix", actix_rt::main)] +#[cfg_attr(feature = "with-hyper", tokio::main)] async fn main() { eprintln!("connecting to localhost:5001..."); diff --git a/ipfs-api/src/client/internal.rs b/ipfs-api/src/client/internal.rs index c94ecb7..9b07572 100644 --- a/ipfs-api/src/client/internal.rs +++ b/ipfs-api/src/client/internal.rs @@ -13,7 +13,7 @@ use crate::{ response::{self, Error}, Client, Request, Response, }; -#[cfg(feature = "actix")] +#[cfg(feature = "with-actix")] use actix_multipart::client::multipart; use bytes::Bytes; use futures::{future, FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt}; @@ -21,16 +21,16 @@ use http::{ uri::{Scheme, Uri}, StatusCode, }; -#[cfg(feature = "hyper")] +#[cfg(feature = "with-hyper")] use hyper::{body, client::Builder}; -#[cfg(feature = "hyper")] +#[cfg(feature = "with-hyper")] use hyper_multipart::client::multipart; -#[cfg(feature = "hyper")] +#[cfg(feature = "with-hyper")] use crate::HyperConnector; use serde::{Deserialize, Serialize}; use serde_json; -#[cfg(feature = "actix")] +#[cfg(feature = "with-actix")] use std::time::Duration; use std::{ fs::File, @@ -45,7 +45,7 @@ fn default() -> T { const FILE_DESCRIPTOR_LIMIT: usize = 127; -#[cfg(feature = "actix")] +#[cfg(feature = "with-actix")] const ACTIX_REQUEST_TIMEOUT: Duration = Duration::from_secs(90); /// Asynchronous Ipfs client. @@ -61,13 +61,13 @@ impl TryFromUri for IpfsClient { /// fn build_with_base_uri(uri: Uri) -> IpfsClient { let client = { - #[cfg(feature = "hyper")] + #[cfg(feature = "with-hyper")] { Builder::default() .pool_max_idle_per_host(0) .build(HyperConnector::new()) } - #[cfg(feature = "actix")] + #[cfg(feature = "with-actix")] { Client::default() } @@ -105,7 +105,7 @@ impl IpfsClient { ::serde_urlencoded::to_string(req)? ); - #[cfg(feature = "hyper")] + #[cfg(feature = "with-hyper")] { url.parse::().map_err(From::from).and_then(move |url| { let builder = http::Request::builder().method(http::Method::POST).uri(url); @@ -119,7 +119,7 @@ impl IpfsClient { req.map_err(From::from) }) } - #[cfg(feature = "actix")] + #[cfg(feature = "with-actix")] { let req = if let Some(form) = form { self.client @@ -171,11 +171,11 @@ impl IpfsClient { where D: Decoder + Send, { - #[cfg(feature = "hyper")] + #[cfg(feature = "with-hyper")] { FramedRead::new(StreamReader::new(res.into_body()), decoder) } - #[cfg(feature = "actix")] + #[cfg(feature = "with-actix")] { FramedRead::new(StreamReader::new(res), decoder) } @@ -193,7 +193,7 @@ impl IpfsClient { { let req = self.build_base_request(req, form)?; - #[cfg(feature = "hyper")] + #[cfg(feature = "with-hyper")] { let res = self.client.request(req).await?; let status = res.status(); @@ -201,7 +201,7 @@ impl IpfsClient { Ok((status, body)) } - #[cfg(feature = "actix")] + #[cfg(feature = "with-actix")] { let mut res = req.await?; let status = res.status(); @@ -280,7 +280,7 @@ impl IpfsClient { OutStream: Stream>, F: 'static + Fn(Response) -> OutStream, { - #[cfg(feature = "hyper")] + #[cfg(feature = "with-hyper")] { self.client .request(req) @@ -304,7 +304,7 @@ impl IpfsClient { }) .try_flatten_stream() } - #[cfg(feature = "actix")] + #[cfg(feature = "with-actix")] { req.err_into() .map_ok(move |mut res| { @@ -332,11 +332,11 @@ impl IpfsClient { /// back a raw stream of bytes. /// fn request_stream_bytes(&self, req: Request) -> impl Stream> { - #[cfg(feature = "hyper")] + #[cfg(feature = "with-hyper")] { self.request_stream(req, |res| res.into_body().err_into()) } - #[cfg(feature = "actix")] + #[cfg(feature = "with-actix")] { self.request_stream(req, |res| res.err_into()) } @@ -433,11 +433,11 @@ impl IpfsClient { /// # fn main() { /// let client = IpfsClient::default(); /// let data = Cursor::new("Hello World!"); - /// #[cfg(feature = "builder")] + /// #[cfg(feature = "with-builder")] /// let add = ipfs_api::request::Add::builder() /// .chunker("rabin-512-1024-2048") /// .build(); - /// #[cfg(not(feature = "builder"))] + /// #[cfg(not(feature = "with-builder"))] /// let add = ipfs_api::request::Add { /// chunker: Some("rabin-512-1024-2048"), /// ..Default::default() @@ -1324,13 +1324,13 @@ impl IpfsClient { /// /// ```no_run /// let client = ipfs_api::IpfsClient::default(); - /// #[cfg(feature = "builder")] + /// #[cfg(feature = "with-builder")] /// let req = ipfs_api::request::FilesLs::builder() /// // .path("/") // defaults to / /// .unsorted(false) /// .long(true) /// .build(); - /// #[cfg(not(feature = "builder"))] + /// #[cfg(not(feature = "with-builder"))] /// let req = ipfs_api::request::FilesLs { /// path: None, // defaults to / /// unsorted: Some(false), @@ -1379,13 +1379,13 @@ impl IpfsClient { /// use ipfs_api::IpfsClient; /// /// let client = IpfsClient::default(); - /// #[cfg(feature = "builder")] + /// #[cfg(feature = "with-builder")] /// let req = ipfs_api::request::FilesMkdir::builder() /// .path("/test/nested/dir") /// .parents(true) /// .flush(false) /// .build(); - /// #[cfg(not(feature = "builder"))] + /// #[cfg(not(feature = "with-builder"))] /// let req = ipfs_api::request::FilesMkdir { /// path: "/test/nested/dir", /// parents: Some(true), @@ -1472,13 +1472,13 @@ impl IpfsClient { /// use ipfs_api::IpfsClient; /// /// let client = IpfsClient::default(); - /// #[cfg(feature = "builder")] + /// #[cfg(feature = "with-builder")] /// let req = ipfs_api::request::FilesRead::builder() /// .path("/test/file.json") /// .offset(1024) /// .count(8) /// .build(); - /// #[cfg(not(feature = "builder"))] + /// #[cfg(not(feature = "with-builder"))] /// let req = ipfs_api::request::FilesRead { /// path: "/test/file.json", /// offset: Some(1024), @@ -1525,13 +1525,13 @@ impl IpfsClient { /// use ipfs_api::IpfsClient; /// /// let client = IpfsClient::default(); - /// #[cfg(feature = "builder")] + /// #[cfg(feature = "with-builder")] /// let req = ipfs_api::request::FilesRm::builder() /// .path("/test/somefile.json") /// .recursive(false) /// .flush(false) /// .build(); - /// #[cfg(not(feature = "builder"))] + /// #[cfg(not(feature = "with-builder"))] /// let req = ipfs_api::request::FilesRm { /// path: "/test/somefile.json", /// recursive: Some(false), @@ -1621,7 +1621,7 @@ impl IpfsClient { /// ```no_run /// let client = ipfs_api::IpfsClient::default(); /// let data = std::io::Cursor::new((1..128).collect::>()); - /// #[cfg(feature = "builder")] + /// #[cfg(feature = "with-builder")] /// let req = ipfs_api::request::FilesWrite::builder() /// .path("/test/outfile.bin") /// .create(false) @@ -1630,7 +1630,7 @@ impl IpfsClient { /// .flush(false) /// // see FilesWriteBuilder for the full set of options /// .build(); - /// #[cfg(not(feature = "builder"))] + /// #[cfg(not(feature = "with-builder"))] /// let req = ipfs_api::request::FilesWrite { /// path: "/test/outfile.bin", /// create: Some(false), @@ -1694,14 +1694,14 @@ impl IpfsClient { /// use std::fs::File; /// /// let client = IpfsClient::default(); - /// #[cfg(feature = "builder")] + /// #[cfg(feature = "with-builder")] /// let req = ipfs_api::request::FilesChcid::builder() /// .path("/test/") /// .cid_version(1) /// .hash("sha3-512") /// .flush(true) /// .build(); - /// #[cfg(not(feature = "builder"))] + /// #[cfg(not(feature = "with-builder"))] /// let req = ipfs_api::request::FilesChcid { /// path: Some("/test/"), /// cid_version: Some(1), @@ -1964,7 +1964,7 @@ impl IpfsClient { /// use ipfs_api::IpfsClient; /// /// let client = IpfsClient::default(); - /// #[cfg(feature = "builder")] + /// #[cfg(feature = "with-builder")] /// let _ = client.ls_with_options(ipfs_api::request::Ls::builder() /// .path("/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n") /// .build() diff --git a/ipfs-api/src/lib.rs b/ipfs-api/src/lib.rs index 62a96c8..df5dea2 100644 --- a/ipfs-api/src/lib.rs +++ b/ipfs-api/src/lib.rs @@ -21,7 +21,7 @@ //! //! ```toml //! [dependencies] -//! ipfs-api = { version = "0.9.0", features = ["actix"], default-features = false } +//! ipfs-api = { version = "0.9.0", features = ["with-actix"], default-features = false } //! ``` //! //! ## Examples @@ -140,21 +140,21 @@ //! ``` //! -#[cfg(feature = "actix")] +#[cfg(feature = "with-actix")] extern crate actix_multipart_rfc7578 as actix_multipart; -#[cfg(feature = "actix")] +#[cfg(feature = "with-actix")] #[macro_use] extern crate derive_more; -#[cfg(feature = "hyper")] +#[cfg(feature = "with-hyper")] extern crate hyper_multipart_rfc7578 as hyper_multipart; -#[cfg(feature = "hyper")] +#[cfg(feature = "with-hyper")] #[macro_use] extern crate failure; extern crate serde; -#[cfg(feature = "builder")] +#[cfg(feature = "with-builder")] #[macro_use] extern crate typed_builder; @@ -167,33 +167,36 @@ mod read; pub mod request; pub mod response; -#[cfg(feature = "actix")] +#[cfg(feature = "with-actix")] use actix_http::{encoding, Payload, PayloadStream}; -#[cfg(feature = "hyper")] +#[cfg(feature = "with-hyper")] use hyper::{self, client::HttpConnector}; -#[cfg(all(feature = "hyper-rustls", feature = "hyper-tls"))] +#[cfg(all(feature = "with-hyper-rustls", feature = "with-hyper-tls"))] compile_error!("Pick only one of the features: hyper-tls, hyper-rustls"); -#[cfg(all(feature = "hyper-tls", not(feature = "hyper-rustls")))] +#[cfg(all(feature = "with-hyper-tls", not(feature = "with-hyper-rustls")))] type HyperConnector = hyper_tls::HttpsConnector; -#[cfg(all(feature = "hyper-rustls", not(feature = "hyper-tls")))] +#[cfg(all(feature = "with-hyper-rustls", not(feature = "with-hyper-tls")))] type HyperConnector = hyper_rustls::HttpsConnector; -#[cfg(all(feature = "hyper", any( - not(any(feature = "hyper-tls", feature = "hyper-rustls")), - all(feature = "hyper-rustls", feature = "hyper-tls"), +#[cfg(all(feature = "with-hyper", any( + not(any(feature = "with-hyper-tls", feature = "with-hyper-rustls")), + all(feature = "with-hyper-rustls", feature = "with-hyper-tls"), )))] type HyperConnector = HttpConnector; -#[cfg(feature = "actix")] +#[cfg(feature = "with-actix")] pub(crate) type Request = awc::SendClientRequest; -#[cfg(feature = "hyper")] +#[cfg(feature = "with-hyper")] pub(crate) type Request = http::Request; -#[cfg(feature = "actix")] +#[cfg(feature = "with-actix")] pub(crate) type Response = awc::ClientResponse>>; -#[cfg(feature = "hyper")] +#[cfg(feature = "with-hyper")] pub(crate) type Response = http::Response; -#[cfg(feature = "actix")] +#[cfg(feature = "with-actix")] pub(crate) type Client = awc::Client; -#[cfg(feature = "hyper")] +#[cfg(feature = "with-hyper")] pub(crate) type Client = hyper::client::Client; + +#[cfg(not(any(feature = "with-actix", feature = "with-hyper")))] +compile_error!("Pick exactly one of these features: with-hyper, with-actix"); diff --git a/ipfs-api/src/request/add.rs b/ipfs-api/src/request/add.rs index 72001c5..889c617 100644 --- a/ipfs-api/src/request/add.rs +++ b/ipfs-api/src/request/add.rs @@ -9,50 +9,50 @@ use crate::request::ApiRequest; use serde::Serialize; -#[cfg_attr(feature = "builder", derive(TypedBuilder))] +#[cfg_attr(feature = "with-builder", derive(TypedBuilder))] #[derive(Serialize, Default)] #[serde(rename_all = "kebab-case")] pub struct Add<'a> { /// Use trickle-dag format for dag generation. - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub trickle: Option, /// Only chunk and hash - do not write to disk. - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub only_hash: Option, /// Wrap files with a directory object. - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub wrap_with_directory: Option, /// Chunking algorithm, `size-[bytes]`, `rabin-[min]-[avg]-[max]` or `buzhash`. - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub chunker: Option<&'a str>, /// Pin this object when adding. Defaults to `true`. - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub pin: Option, /// Use raw blocks for leaf nodes. (experimental). - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub raw_leaves: Option, /// CID version. Defaults to 0 unless an option that depends on CIDv1 is passed. /// (experimental). - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub cid_version: Option, /// Hash function to use. Implies CIDv1 if not sha2-256. (experimental). Default: /// `sha2-256`. - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub hash: Option<&'a str>, /// Inline small blocks into CIDs. (experimental). - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub inline: Option, /// Maximum block size to inline. (experimental). Default: `32`. - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub inline_limit: Option, } diff --git a/ipfs-api/src/request/files.rs b/ipfs-api/src/request/files.rs index 498faa9..64cf874 100644 --- a/ipfs-api/src/request/files.rs +++ b/ipfs-api/src/request/files.rs @@ -34,17 +34,17 @@ impl<'a> ApiRequest for FilesFlush<'a> { const PATH: &'static str = "/files/flush"; } -#[cfg_attr(feature = "builder", derive(TypedBuilder))] +#[cfg_attr(feature = "with-builder", derive(TypedBuilder))] #[derive(Serialize, Default)] pub struct FilesLs<'a> { #[serde(rename = "arg")] - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub path: Option<&'a str>, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub long: Option, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] #[serde(rename = "U")] pub unsorted: Option, } @@ -53,23 +53,23 @@ impl<'a> ApiRequest for FilesLs<'a> { const PATH: &'static str = "/files/ls"; } -#[cfg_attr(feature = "builder", derive(TypedBuilder))] +#[cfg_attr(feature = "with-builder", derive(TypedBuilder))] #[derive(Serialize, Default)] #[serde(rename_all = "kebab-case")] pub struct FilesMkdir<'a> { #[serde(rename = "arg")] pub path: &'a str, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub parents: Option, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub hash: Option<&'a str>, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub cid_version: Option, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub flush: Option, } @@ -92,16 +92,16 @@ impl<'a> ApiRequest for FilesMv<'a> { const PATH: &'static str = "/files/mv"; } -#[cfg_attr(feature = "builder", derive(TypedBuilder))] +#[cfg_attr(feature = "with-builder", derive(TypedBuilder))] #[derive(Serialize, Default)] pub struct FilesRead<'a> { #[serde(rename = "arg")] pub path: &'a str, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub offset: Option, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub count: Option, } @@ -109,16 +109,16 @@ impl<'a> ApiRequest for FilesRead<'a> { const PATH: &'static str = "/files/read"; } -#[cfg_attr(feature = "builder", derive(TypedBuilder))] +#[cfg_attr(feature = "with-builder", derive(TypedBuilder))] #[derive(Serialize, Default)] pub struct FilesRm<'a> { #[serde(rename = "arg")] pub path: &'a str, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub recursive: Option, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub flush: Option, } @@ -139,38 +139,38 @@ impl<'a> ApiRequest for FilesStat<'a> { const PATH: &'static str = "/files/stat"; } -#[cfg_attr(feature = "builder", derive(TypedBuilder))] +#[cfg_attr(feature = "with-builder", derive(TypedBuilder))] #[derive(Serialize, Default)] #[serde(rename_all = "kebab-case")] pub struct FilesWrite<'a> { #[serde(rename = "arg")] pub path: &'a str, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub create: Option, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub truncate: Option, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub parents: Option, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub offset: Option, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub count: Option, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub raw_leaves: Option, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub hash: Option<&'a str>, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub cid_version: Option, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub flush: Option, } @@ -178,21 +178,21 @@ impl<'a> ApiRequest for FilesWrite<'a> { const PATH: &'static str = "/files/write"; } -#[cfg_attr(feature = "builder", derive(TypedBuilder))] +#[cfg_attr(feature = "with-builder", derive(TypedBuilder))] #[derive(Serialize, Default)] #[serde(rename_all = "kebab-case")] pub struct FilesChcid<'a> { - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] #[serde(rename = "arg")] pub path: Option<&'a str>, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub hash: Option<&'a str>, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub cid_version: Option, - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub flush: Option, } diff --git a/ipfs-api/src/request/ls.rs b/ipfs-api/src/request/ls.rs index d3c932c..204d067 100644 --- a/ipfs-api/src/request/ls.rs +++ b/ipfs-api/src/request/ls.rs @@ -9,20 +9,20 @@ use crate::request::ApiRequest; use crate::serde::Serialize; -#[cfg_attr(feature = "builder", derive(TypedBuilder))] +#[cfg_attr(feature = "with-builder", derive(TypedBuilder))] #[derive(Serialize, Default)] #[serde(rename_all = "kebab-case")] pub struct Ls<'a> { #[serde(rename = "arg")] pub path: &'a str, /// Resolve linked objects to find out their types. Default: `true` - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub resolve_type: Option, /// Resolve linked objects to find out their file size. Default: `true` - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub size: Option, /// Enable experimental streaming of directory entries as they are traversed. - #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))] + #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))] pub stream: Option, } diff --git a/ipfs-api/src/response/error.rs b/ipfs-api/src/response/error.rs index c98d183..996a313 100644 --- a/ipfs-api/src/response/error.rs +++ b/ipfs-api/src/response/error.rs @@ -9,8 +9,8 @@ use crate::serde::Deserialize; use std::string::FromUtf8Error; -#[cfg_attr(feature = "actix", derive(Display), display(fmt = "{}", message))] -#[cfg_attr(feature = "hyper", derive(Fail), fail(display = "{}", message))] +#[cfg_attr(feature = "with-actix", derive(Display), display(fmt = "{}", message))] +#[cfg_attr(feature = "with-hyper", derive(Fail), fail(display = "{}", message))] #[derive(Debug, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct ApiError { @@ -18,106 +18,106 @@ pub struct ApiError { pub code: u8, } -#[cfg_attr(feature = "actix", derive(Display))] -#[cfg_attr(feature = "hyper", derive(Fail))] +#[cfg_attr(feature = "with-actix", derive(Display))] +#[cfg_attr(feature = "with-hyper", derive(Fail))] #[derive(Debug)] pub enum Error { /// Foreign errors. - #[cfg(feature = "hyper")] - #[cfg_attr(feature = "hyper", fail(display = "hyper client error '{}'", _0))] + #[cfg(feature = "with-hyper")] + #[cfg_attr(feature = "with-hyper", fail(display = "hyper client error '{}'", _0))] Client(hyper::Error), - #[cfg(feature = "actix")] + #[cfg(feature = "with-actix")] #[cfg_attr( - feature = "actix", + feature = "with-actix", display(fmt = "actix client payload error '{}'", _0) )] ClientPayload(awc::error::PayloadError), - #[cfg(feature = "actix")] + #[cfg(feature = "with-actix")] #[cfg_attr( - feature = "actix", + feature = "with-actix", display(fmt = "actix client send request error '{}'", _0) )] ClientSend(awc::error::SendRequestError), - #[cfg_attr(feature = "actix", display(fmt = "http error '{}'", _0))] - #[cfg_attr(feature = "hyper", fail(display = "http error '{}'", _0))] + #[cfg_attr(feature = "with-actix", display(fmt = "http error '{}'", _0))] + #[cfg_attr(feature = "with-hyper", fail(display = "http error '{}'", _0))] Http(http::Error), - #[cfg_attr(feature = "actix", display(fmt = "json parse error '{}'", _0))] - #[cfg_attr(feature = "hyper", fail(display = "json parse error '{}'", _0))] + #[cfg_attr(feature = "with-actix", display(fmt = "json parse error '{}'", _0))] + #[cfg_attr(feature = "with-hyper", fail(display = "json parse error '{}'", _0))] Parse(serde_json::Error), - #[cfg_attr(feature = "actix", display(fmt = "utf8 decoding error '{}'", _0))] - #[cfg_attr(feature = "hyper", fail(display = "utf8 decoding error '{}'", _0))] + #[cfg_attr(feature = "with-actix", display(fmt = "utf8 decoding error '{}'", _0))] + #[cfg_attr(feature = "with-hyper", fail(display = "utf8 decoding error '{}'", _0))] ParseUtf8(FromUtf8Error), - #[cfg_attr(feature = "actix", display(fmt = "uri error '{}'", _0))] - #[cfg_attr(feature = "hyper", fail(display = "uri error '{}'", _0))] + #[cfg_attr(feature = "with-actix", display(fmt = "uri error '{}'", _0))] + #[cfg_attr(feature = "with-hyper", fail(display = "uri error '{}'", _0))] Url(http::uri::InvalidUri), - #[cfg_attr(feature = "actix", display(fmt = "io error '{}'", _0))] - #[cfg_attr(feature = "hyper", fail(display = "io error '{}'", _0))] + #[cfg_attr(feature = "with-actix", display(fmt = "io error '{}'", _0))] + #[cfg_attr(feature = "with-hyper", fail(display = "io error '{}'", _0))] Io(std::io::Error), - #[cfg_attr(feature = "actix", display(fmt = "url encoding error '{}'", _0))] - #[cfg_attr(feature = "hyper", fail(display = "url encoding error '{}'", _0))] + #[cfg_attr(feature = "with-actix", display(fmt = "url encoding error '{}'", _0))] + #[cfg_attr(feature = "with-hyper", fail(display = "url encoding error '{}'", _0))] EncodeUrl(serde_urlencoded::ser::Error), /// An error returned by the Ipfs api. - #[cfg_attr(feature = "actix", display(fmt = "api returned error '{}'", _0))] - #[cfg_attr(feature = "hyper", fail(display = "api returned error '{}'", _0))] + #[cfg_attr(feature = "with-actix", display(fmt = "api returned error '{}'", _0))] + #[cfg_attr(feature = "with-hyper", fail(display = "api returned error '{}'", _0))] Api(ApiError), /// A stream error indicated in the Trailer header. #[cfg_attr( - feature = "actix", + feature = "with-actix", display(fmt = "api returned an error while streaming: '{}'", _0) )] #[cfg_attr( - feature = "hyper", + feature = "with-hyper", fail(display = "api returned an error while streaming: '{}'", _0) )] StreamError(String), /// API returned a trailer header with unrecognized value. #[cfg_attr( - feature = "actix", + feature = "with-actix", display(fmt = "api returned a trailer header with unknown value: '{}'", _0) )] #[cfg_attr( - feature = "hyper", + feature = "with-hyper", fail(display = "api returned a trailer header with unknown value: '{}'", _0) )] UnrecognizedTrailerHeader(String), #[cfg_attr( - feature = "actix", + feature = "with-actix", display(fmt = "api returned unknwon error '{}'", _0) )] #[cfg_attr( - feature = "hyper", + feature = "with-hyper", fail(display = "api returned unknwon error '{}'", _0) )] Uncategorized(String), } -#[cfg(feature = "hyper")] +#[cfg(feature = "with-hyper")] impl From for Error { fn from(err: hyper::Error) -> Error { Error::Client(err) } } -#[cfg(feature = "actix")] +#[cfg(feature = "with-actix")] impl From for Error { fn from(err: awc::error::SendRequestError) -> Error { Error::ClientSend(err) } } -#[cfg(feature = "actix")] +#[cfg(feature = "with-actix")] impl From for Error { fn from(err: awc::error::PayloadError) -> Error { Error::ClientPayload(err) -- cgit v1.2.3